<<< BufferedReader, reading text file | Index | Formatted input with Scanner and FileReader >>> |
Code that reads a Book object from a delimited text file
// implements buffered reading from a character stream BufferedReader in = new BufferedReader( // implements reading character files new FileReader("books.txt")); // read the next line of the file String line = in.readLine(); // parse the line into its columns String[] columns = line.split("\t"); String code = columns[0]; String description = columns[1]; String price = columns[2]; // create a book object from the data in the columns Book p = new Book( code, description, Double.parseDouble(price)); // print the Book object System.out.println(p); // close the input stream in.close();
Sample output for code that reads a Book object from a delimited text file
Code: book Description: Beginning Java Programming Price: $49.50
<<< BufferedReader, reading text file | Index | Formatted input with Scanner and FileReader >>> |