读书人

请问JEditorPane显示大文件的性能有关

发布时间: 2012-03-26 15:46:55 作者: rapoo

请教JEditorPane显示大文件的性能问题问题
编写了一个XEditorPane 类继承自JEditorPane

public class XEditorPane extends
JEditorPane implements KeyListener {
...

/*清空内容,显示文件*/
public void onViewFile(String sFilePath, String sFileName) {
clear();
FileReader a = null;
try {
a = new FileReader(sFilePath);
read(a, null);

} catch (FileNotFoundException e) {
} catch (IOException e) {
} finally {
try {
if (a != null) {
a.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
a = null;
}
installUndoRedo();
setCursor(old);
}

public void clear() {
Document doc = getDocument();
setVisible(false);
try {
doc.remove(0, doc.getLength());
} catch (BadLocationException ex1) {
}
setVisible(true);
repaint();
}

在文件比较大的时候,比如1MB时,读入文件到显示的时候占用时间非常长,cpu也很高,请问各位大侠有没有什么好方法?

[解决办法]
推荐:
http://www.elearning.gov.cn/elearning/user/findclass.do?method=courselist&categoryid=57982540b6cd11d993d0f770c0a83c70&id=2
------解决方案--------------------


可否从IO上提高性能

比如说BufferedReader

读书人网 >J2SE开发

热点推荐