This code first creates a file (MyFile.txt) and add the data using DataOutputStream. DataOutputStream have special methods to write different type of data like writeInt() uses for integer, writeChars() uses for string.

 package MyProject;

import java.io.*;

public class FileOutput {

  public static void main(String[] args) {

    FileOutputStream fos; 
    DataOutputStream dos;

    try {

      File file= new File("C:\\MyFile.txt");
      fos = new FileOutputStream(file);
      dos=new DataOutputStream(fos);
      dos.writeInt(2333);
      dos.writeChars("Hello");

    } catch (IOException e) {
      e.printStackTrace();
    }

  }

}