Instantly share code, notes, and snippets.

Embed
What would you like to do?
write ints
import java.io.*;
class WriteInts
{
public static void main ( String[] args )
{
String fileName = "intData.dat" ;
int value0 = 0, value1 = 1, value255 = 255, valueM1 = -1;
try
{
DataOutputStream out = new DataOutputStream( new FileOutputStream( fileName ) );
out.writeInt( value0 ); // The writeInt method of DataOutputStream
out.writeInt( value1 ); // knows how to deal with ints
out.writeInt( value255 );
out.writeInt( valueM1 );
out.close();
}
catch ( IOException iox )
{
System.out.println("Problem writing " + fileName );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment