RandomAccessFile
The RandomAccessFile class in the Java IO API allows you to move around a file and read from it or write to it as you please.
Here is a thing the JavaDoc forgets to mention: The read() method increments the file pointer to point to the next byte in the file after the byte just read! This means that you can continue to call read() without having to manually move the file pointer.
import java.io.RandomAccessFile;
public class RandomAccessFileTest {
public static void main(String args[]){
try{
RandomAccessFile file = new RandomAccessFile(
"c:\\work\\hello\\helloworld.txt", "rw");
file.writeBytes("hello world!");
file.writeChar('A');
file.writeInt(1);
file.writeBoolean(true);
file.writeFloat(1.0f);
file.writeDouble(1.0);
file.close();
}catch(Exception e){
e.printStackTrace();
}
}
}