Home » Java » Cannot convert file to string for very large file?

Cannot convert file to string for very large file?

Posted by: admin April 25, 2018 Leave a comment

Questions:

I have tried to implement a bufferedreader in order to convert a .txt file, specifically the Iliad to a string. I have tested small files and they have worked but the larger do not. When I attempt to print fileString after the while loop it finished, no output is shown. Here’s my code.

String fileString = "";
    String line = "";
    char readChar;

    BufferedReader br;
    try {
        br = new BufferedReader(new FileReader(inputFile));
        while((line=br.readLine())!=null)
        {
            fileString = fileString + line;System.out.println(fileString);
        }
        br.close();
    } catch (IOException e) {
        e.printStackTrace();
    }System.out.println(fileString);
Answers: