Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Please I need help with readLine and readDouble

807597Feb 15 2005 — edited Feb 15 2005
hello everyone I have some code that is not giving the output that it should
Example when I use readInt or readDouble it not giving me the correct set of data I have in an external file the code is below and the data input is here

thanks in advance

19.99 12 Java T-shirt
9.99 8 Java Mug

import java.io.*;

public class readDatastream {

    public static void main(String[] args) throws IOException {

 

        // read it in again

        DataInputStream in = new DataInputStream(new

             FileInputStream("invoice1.txt"));

 

        double price;

        int unit;

        String desc ="test";

        double total = 0.0;

 

        try {

            while (true) {

                price = in.readFloat();

                in.readChar();       // throws out the tab

                unit = in.readInt();

                in.readChar();       // throws out the tab

                desc = in.readLine();

                System.out.println("You've ordered " + unit + " units of " +

                      desc + " at $" + price);

                total = total + unit * price;

            }

        } catch (EOFException e) {

        }

        System.out.println("For a TOTAL of: $" + total);

        in.close();

    }

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 15 2005
Added on Feb 15 2005
20 comments
319 views