I am reading/writing/updating large data files and the RandomAccessFile() seems the best fit. The only problem is that using the primitive read member functions like readInt(), readFloat() etc takes too long. It seems the read (byte,int off, int len) function would help me with buffering my reads, but I'm still green under the collar when it comes to manipulating Java primitive types. I'm used to c where I can use memcpy to copy from a buffer into an int, or a float. How do I read in a block of bytes and then save it as the appropriate types? What is the equiv in Java for: char buffer; int ival; float fval; char cval; memcpy (&ival, buffer, 4); memcpy (&fval, &buffer, 4); memcpy (&cval, &buffer, 1);
There are a variety of ways to encode a String - you may also want to user the read(byte) method and then use a new String[byte, String) constructor to specify the encoding used in the byte array. It depends on exactly how the String data was originally written. But if it was written using writeUTF(String), you can read it with readUTF().
I should add that in my experience, RandomAccessFile is usually pretty slow for most applications. It's a jack-of-all-trades class; it does a lot of different things, but isn't particularly good at anyof them. You can usually create a combination of streams that does what you want with reater efficiency.