幸好找到 ANGEL SKY 的博客。用ISO8859_1編碼轉(zhuǎn)換。
代碼片斷:
String bodyText = null;
DefaultStyledDocument styledDoc = new DefaultStyledDocument(); //javax.swing.text.Document的一個(gè)實(shí)例
try {
InputStream is = new FileInputStream(new File("data/java.swing.text讀RTF文檔測(cè)試.rtf"));
new RTFEditorKit().read(is, styledDoc, 0);
bodyText = new String(styledDoc.getText(0, styledDoc.getLength()).getBytes("ISO8859_1")); //提取文本
} catch (IOException e) {
throw new DocumentHandlerException("不能從RTF中摘錄文本!", e);
} catch (BadLocationException e) {
throw new DocumentHandlerException("不能從RTF中摘錄文本!", e);
}
System.out.println(bodyText);
DefaultStyledDocument styledDoc = new DefaultStyledDocument(); //javax.swing.text.Document的一個(gè)實(shí)例
try {
InputStream is = new FileInputStream(new File("data/java.swing.text讀RTF文檔測(cè)試.rtf"));
new RTFEditorKit().read(is, styledDoc, 0);
bodyText = new String(styledDoc.getText(0, styledDoc.getLength()).getBytes("ISO8859_1")); //提取文本
} catch (IOException e) {
throw new DocumentHandlerException("不能從RTF中摘錄文本!", e);
} catch (BadLocationException e) {
throw new DocumentHandlerException("不能從RTF中摘錄文本!", e);
}
System.out.println(bodyText);