I have a large text file but doesn\'t have any line break. It just contains a long String (1 huge line of String with all ASCII characters), but so far anything works just f
A single String can be only 2 billion characters long and will use 2 byte per character, so if you could read a 5 GB line it would use 10 GB of memory.
I suggest you read the text in blocks.
Reader reader = new FileReader("input.txt");
try {
char[] chars = new char[8192];
for(int len; (len = reader.read(chars)) > 0;) {
// process chars.
}
} finally {
reader.close();
}
This will use about 16 KB regardless of the size of the file.