Filter streams can be successively layered. For example, in the WriteBinFile program ,we could use a buffered DataOutputStream,
WriteBinFile
import java.io.*;
public class WriteBinFile
{
public static void main(String[] args) throws
IOException
{
FileOutputStream fileOut = new FileOutputStream(“File1.dat”);
BufferedOutputStream buffOut = new BufferedOutputStream(fileOut);
DataOutputStream out= new DataOutputStream(buffOut);
String[] item = {"ice axe", "crampons",
"sleeping bag", "mittens"};
float[] price = {74.99f, 44.95f, 100.00f, 37.50f};
int[] qty = {2, 1, 1, 3};
char fieldSeparator = ';';
char lineSeparator = '\n';
int i;
for (i = 0; i < 4; i++)
{
out.writeChars(item[i]);
out.writeChar(fieldSeparator);
out.writeFloat(price[i]);
out.writeChar(fieldSeparator);
out.writeInt(qty[i]);
out.writeChar(lineSeparator);
}
out.close();
}
}
Wrapping Filter Streams in Java
Tags
# Input/Output
# Wrapping Filter Streams
Share This
Wrapping Filter Streams
Labels:
Input/Output,
Wrapping Filter Streams
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment