I have tried to explain the coding in program of the Data Streams. The following program defines some constants containing the name of the data file :
Code:
static final String dataFile = "dataexample";
static final double[] prices = { 17.99, 11.99, 12.99, 7.99, 6.99 };
static final int[] units = { 14, 7, 16, 22, 44 };
static final String[] descs = { "Java Band",
"Java Glass",
"Duke Juggling Dolls",
"Java Stapler",
"Java Locket" };
// Then DataStreams opens an output stream.
out = new DataOutputStream(new
BufferedOutputStream(new FileOutputStream(dataFile)));
// DataStreams writes out the records and closes the output stream.
for (int i = 0; i < prices.length; i ++) {
out.writeDouble(prices[i]);
out.writeInt(units[i]);
out.writeUTF(descs[i]);
}
Bookmarks