Write int to a file in Java
Description
The following code shows how to write int to a file.
Example
/* ww w. j a va 2 s. c o m*/
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws Exception {
FileInputStream fin = new FileInputStream("myfile.dat");
DataInputStream din = new DataInputStream(fin);
int theNumber = din.readInt();
System.out.println(theNumber);
din.close();
}
}