我读取文件并将文本(大小约为4000KB)设置为JTextArea。它冻结了我的申请。以下是我的代码段。我很感激你的建议......
public void setText(final JTextArea textArea)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
BufferedReader from = null;
try
{
from = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
System.out.println("Started..........");
textArea.read(from, file.getName());
System.out.println("Completed..........");
}
catch (Exception ex)
{
Logger.getLogger(FileTools.class.getName()).log(Level.SEVERE, null, ex);
}
finally
{
try
{
from.close();
}
catch (IOException ex)
{
Logger.getLogger(FileTools.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
}