Write UTF String, integer and double with DataOutputStream
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
public class Main {
public static void main(String[] argv) throws Exception {
FileOutputStream fileOut = new FileOutputStream("data.txt");
BufferedOutputStream buffer = new BufferedOutputStream(fileOut);
DataOutputStream dataOut = new DataOutputStream(buffer);
dataOut.writeUTF("Hello!");
dataOut.writeInt(4);
dataOut.writeDouble(100.0);
dataOut.close();
buffer.close();
fileOut.close();
}
}
Related examples in the same category