FileDocCategorySizeDatePackage
TestBinaryOutputStream.javaAPI DocExample799Sun Feb 24 10:30:14 GMT 2002None

TestBinaryOutputStream.java

import java.io.*;

public class TestBinaryOutputStream {
	public static void main(String[] args)  throws IOException {
		// Set up the streams
		File outFile = new File("C:\\Sample1.dat");
		
		// FileOutputStream writes bytes
		FileOutputStream ofs = new FileOutputStream(outFile);
		
		// DataOuputStream writes floats, ints, doubles
		DataOutputStream outDataStream = new DataOutputStream(ofs);
		
		// Try writing a few primitive values to the stream.
		outDataStream.writeInt(4);
		outDataStream.writeInt(-1);
                String s = "Hello world";
                outDataStream.writeUTF(s);
                outDataStream.writeDouble(3.14159D);
                outDataStream.writeLong(1000L);
                outDataStream.writeChar('A');
		outDataStream.close();
	}
}