I'm trying to show on screen a textfile content using JavaFX textarea
. I success doing it with small files, but with big ones everything becomes too slow. File with size 64KB
was read in 1 second, and it takes 2 minutes to display it. There is code:
try (FileReader fileReader = new FileReader(file); BufferedReader reader = new BufferedReader(fileReader)) {
char[] buf = new char[102400];
int haveRead;
while ((haveRead = reader.read(buf)) != -1) {
buf = Arrays.copyOf(buf, haveRead);
String str = new String(buf);
textArea.appendText(str);
log.trace(str);
}
} catch (IOException e) {
log.error("Error while reading file", e);
}
Logging shows that even with multithreading almost all time program waiting for
textArea.appendText(str);
What to do? Is there faster implementation or mine faults in code? or the only way is to do buffer of displaying text, somehow overriding the behavior of textarea slider?