I know that to write a value(integer) to a binary file I can use the fileoutputstream to do it.
Expand|Select|Wrap|Line Numbers
- try
- {
- // Create an output stream to the file.
- FileOutputStream file_output = new FileOutputStream (outFile);
- //for(int i = 0; i < cInt.length; i++)
- file_output.write(100);
- file_output.write(200);
- file_output.write(300);
- // Close file when finished with it..
- file_output.close ();
- }
Expand|Select|Wrap|Line Numbers
- int bInt = 0;
- try
- {
- // Wrap the FileInputStream with a DataInputStream
- FileInputStream file_input = new FileInputStream (inFile);
- DataInputStream data_in = new DataInputStream (file_input);
- while(true)
- {
- try
- {
- bInt = data_in.readInt();
- }
- catch (EOFException eof)
- {
- //end of file
- break;
- }
- System.out.println("Test: "+bInt);
- }
- data_in.close ();
- }
- catch(IOException e)
- {
- System.out.println ( "IO Exception =: " + e );
- System.exit(0);
- }