Here would be my first pass, assuming that memory is not an issue (ha).
- Get the file size as it sits on disk (File.length).
- Allocate that size buffer.
- Load the whole thing in one shot (InputStream.read(byte[])).
- Break that String into substrings entirely in memory.
- Do Stuff (tm)
- Reverse above to save.
Keep in mind that Java stores character data with UCS-16 internally, which means that your nice ASCII file is going to take x2 the size on disk to account for the "expansion." e.g. You have a 4,124 byte foo.txt file will be at least 8,248 bytes in memory.
Everything else is going to be slower, because the application will be designed to deal with some sort of buffering and wrapping (in particular, to deal with not having enough memory to deal with the file size).
Good luck!