import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class InputOutputDemoBinaryFile {
public static void main(String[] a) throws Exception {
//Write primitive values to a binary file "java2s.dat":
DataOutputStream dos = new DataOutputStream(new FileOutputStream(
"java2s.dat"));
dos.writeInt(228);
dos.writeChar(' ');
dos.writeUTF("Java Source and Support at www.java2java.com");
dos.close();
//Read primitive values from binary file "java2s.dat":
DataInputStream dis = new DataInputStream(new FileInputStream(
"java2s.dat"));
System.out.println(dis.readInt() + "|" + dis.readChar() + "|"
+ dis.readUTF());
}
}
|