Write UTF String, integer and double with DataOutputStream : FileOutputStream « File Input Output « Java






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

1.File IO
2.Copy Bytes between FileInputStream and FileOutputStream
3.Copy byte between FileInputStream and FileOutputStream
4.Write byte array to a file using FileOutputStream
5.Create DataOutputStream from FileOutputStream
6.Write double to a file using DataOutputStream
7.Append output to file using FileOutputStream
8.Create FileOutputStream object from File object
9.Create FileOutputStream object from String file path
10.Write file using FileOutputStream
11.Use FileOutputStream to write the bytes to a file.
12.Write data with FileOutputStream
13.Split file
14.Rollover FileOutputStream