Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created November 23, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/bcd1f00395918334339e44a1bfe41296 to your computer and use it in GitHub Desktop.
Save thinkphp/bcd1f00395918334339e44a1bfe41296 to your computer and use it in GitHub Desktop.
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