Created
November 23, 2018 19:04
-
-
Save thinkphp/bcd1f00395918334339e44a1bfe41296 to your computer and use it in GitHub Desktop.
write ints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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