import java.io.*; public class BinRead{ public static void main(String[ ] xx) throws IOException{ double price; int unit; String desc; DataInputStream dis = new DataInputStream( new FileInputStream("testfile.txt") ); double total=0; try { while (true) { price = dis.readDouble(); dis.readChar(); // throws out the tab unit = dis.readInt(); dis.readChar(); // throws out the tab desc = dis.readUTF(); //好像沒讀走 newline dis.readChar(); // 把 newline 讀掉 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); dis.close(); }//main }