private void doRead(File file) {
FileInputStream fous = null;
{
ObjectInputStream ois = null;
try {
fous = new FileInputStream(file);
ois = new ObjectInputStream(fous);
text = (JTextPane) ois.readUnshared();
if (text != null) {
System.out.println("ok");
}
scrollPane = new JScrollPane(text);
this.getContentPane().add(scrollPane);
SwingUtilities.updateComponentTreeUI(text);
} catch (IOException ex) {
Logger.getLogger(TestJTextArea.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(TestJTextArea.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fous.close();
} catch (IOException ex) {
Logger.getLogger(TestJTextArea.class.getName()).log(Level.SEVERE, null, ex);
}
try {
ois.close();
} catch (IOException ex) {
Logger.getLogger(TestJTextArea.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
private void doSave(File file) {
FileOutputStream fous = null;
{
ObjectOutputStream oos = null;
try {
fous = new FileOutputStream(file);
oos = new ObjectOutputStream(fous);
oos.writeUnshared(text);
oos.flush();
} catch (IOException ex) {
Logger.getLogger(TestJTextArea.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fous.close();
} catch (IOException ex) {
Logger.getLogger(TestJTextArea.class.getName()).log(Level.SEVERE, null, ex);
}
try {
oos.close();
} catch (IOException ex) {
Logger.getLogger(TestJTextArea.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
回复 更多评论