Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

problem in using of textArea

  Asked By: Darla    Date: Jun 13    Category: Java    Views: 805
  

I am facing a problem to display a file bigger than 30-40kB on textArea.
Scrollbar works very slowly and cpu being engagged .it takes much time
to display while Notpad,Word & other editor can load and display files upper than 1MB in a few milisec and scroll them very smoothly.
Which technic I should use in using of textArea?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Alan Palmer     Answered On: Jun 13

Notice to this code and I hope solve your problem  :


String finalFileData = null;
File file  = new File (filePath); // filePath is a path + name
try {
FileReader freader = null;
try {
freader = new FileReader(file); // create FileReader
StringBuffer fileData = new StringBuffer((int) file.length());
char[] chars = new char[SOME_BUFFER_SIZE];
int c = freader.read(chars); // read initial buffer into 'chars'
while (c > 0) {
fileData.append(chars, 0, c); // append string from 'chars' to
'fileData'
c = freader.read(chars); // read next buffer into 'chars'
}
finalFileData = fileData.toString();
} finally {
if (freader != null)
freader.close();
}
} catch (Exception e) {
finalFileData = null;
}

 
Didn't find what you were looking for? Find more on problem in using of textArea Or get search suggestion and latest updates.




Tagged: