How do you know it is not working? Maybe it is working, only taking a long time. You appear to be using the + operator on Strings several million times. That can have a very severe performance overhead; try the append() method of a StringBuilder instead.
William Brogden wrote:I can't see any reason to read line by line.
If this was my problem, I would get the file length, create a char the right size and use the InputStreamReader method to read straight to the char.
Not really viable unless one know the relationship between the number of bytes and the number of chars. If you absolutely have to do this, and one rarely has to, and if you you not willing to use "apache.commons.io" then I think the easiest way to to this is to just read all the bytes into an array using DataInputStream#readFully(). One get the file length from the File object. One then converts the byte array to a String specifying the character encoding to use.
Note that a file can be longer than 2 GByte but a byte array is limited to 2 GBytes so even if one had enough memory one can't read guarantee to read the whole of a file into memory.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.