<<< RandomAccessFile implements DataOutput and DataInput interfaces | Index | RandomAccessFile example: reading binary file >>> |
Code that writes data to a file
RandomAccessFile booksFile = new RandomAccessFile("books.ran", "rw"); // write 3 records that contain codes and prices // to the file String[] codes = {"java", "jsps", "txtp"}; double[] prices = {49.5, 49.5, 20.0}; for (int i = 0; i < codes.length; i++) { booksFile.writeChars(codes[i]); booksFile.writeDouble(prices[i]); } booksFile.close();
<<< RandomAccessFile implements DataOutput and DataInput interfaces | Index | RandomAccessFile example: reading binary file >>> |