我有下面的代碼嘗試保存爲RTF的JTextPane的內容。儘管在下面的代碼中創建了一個文件,但它是空的!Java JTextPane RTF保存
關於我在做什麼錯的任何提示? (像往常一樣,不要忘記我是一個新手!)
if (option == JFileChooser.APPROVE_OPTION) {
////////////////////////////////////////////////////////////////////////
//System.out.println(chooser.getSelectedFile().getName());
//System.out.println(chooser.getSelectedFile().getAbsoluteFile());
///////////////////////////////////////////////////////////////////////////
StyledDocument doc = (StyledDocument)textPaneHistory.getDocument();
RTFEditorKit kit = new RTFEditorKit();
BufferedOutputStream out;
try {
out = new BufferedOutputStream(new FileOutputStream(chooser.getSelectedFile().getName()));
kit.write(out, doc, doc.getStartPosition().getOffset(), doc.getLength());
} catch (FileNotFoundException e) {
} catch (IOException e){
} catch (BadLocationException e){
}
}
編輯:一個HTMLEditorKit如果我使用一個HTMLEditorKit它的工作原理和多數民衆贊成我真正想要的。解決了!
@ikurtz你可以回答你自己的問題(沒有聲望),這有助於其他人正在尋找答案。 – stacker 2010-04-27 21:39:32
@stacker:是的,一旦論壇允許我這樣做,我會按照解決方案進行解決。我認爲有一天我可以提交我的答案。 – iTEgg 2010-04-27 21:46:54