pncorp
asked on
Java handling large text file
I'm trying to access a large text file and handle the data as if it were a string. I've never had to access a file larger than a few megs, and this is over 100mb. Any help is appreciated.
Why do you need to access it as a String. Are you sure you do?
ASKER
It doesn't have to be a String, but I need to be able to create strings by using indexes like I would use to create a substring from a string.
OK. That wouldn't require you to read the whole file into memory fortunately. Just use a RandomAccessFile
e.g. to read a String of 64 characters halfway into the file:
RandomAccessFile raf = new RandomAccessFile("x.txt", "r");
raf.seek(raf.length() / 2);
byte[] buffer = new byte[64];
raf.read(buffer);
String s = new String(buffer);
ASKER
So how would I create a string from charcter 1000 - 1050?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, you're awesome!
:-)
:-)
Actually, you should use readFully, not read
Actually, you should use readFully, not read