Read large text file in java, infeasible?

wanasa

New Member
I'm using the following method to read a file into a \[code\]JTextArea\[/code\]:\[code\]public void readFile(File file) throws java.io.FileNotFoundException, java.io.IOException { if(file == null) return; jTextArea1.setText(""); try(BufferedReader reader = new BufferedReader(new FileReader(file))){ String line = ""; while((line=reader.readLine())!=null){ jTextArea.append(line + "\n"); } }}\[/code\]It works OK with a normal-sized file (a few hundred kilobytes), but when I tested a 30000-line file of 42 MB that Notepad can open in about 5 seconds, my file reader took forever. I couldn't wait for it to finish; I had waited for about 15-20 minutes and it was still working consuming 30% of my CPU usage.Could you please give me a solution for this? I'm handling with text files only, not binary files, and all I know is using \[code\]BufferedReader\[/code\] is the best.
 
Back
Top