<<< DataInputStream methods | Index | DataOutputStream: writing binary strings >>> |
Code that reads Book objects from a binary file
DataInputStream in = new DataInputStream( new BufferedInputStream( new FileInputStream("myfile.dat"))); while (in.available() > 0) { // read book data from a file String code = in.readUTF(); String description = in.readUTF(); double price = in.readDouble(); // create the Book object from its data Book p = new Book(code, description, price); } // close the input stream in.close();
<<< DataInputStream methods | Index | DataOutputStream: writing binary strings >>> |