gpt4 book ai didi

java - JTextpane 不会在文件中保存属性文本和图标

转载 作者:太空宇宙 更新时间:2023-11-04 09:45:31 26 4
gpt4 key购买 nike

我试图将 Java 文本 Pane 的文档保存为“rtf”文件Document的内容被保存到文件中,但上标、下标、图标等属性不被保存

````java


StyledDocument docx =(DefaultStyledDocument) editor.getDocument();
RTFEditorKit kit = new RTFEditorKit();
System.out.println(kit.getContentType()) ;
int startPos = docx.getStartPosition().getOffset();
int docLen = docx.getLength();
File file = new File("E:\\file1.rtf");
BufferedOutputStream out =null ;
try {
out= new BufferedOutputStream(new FileOutputStream(file));
kit.write(out, docx,startPos ,docLen);
out.close();
}
catch (Exception ex) {

}

````

最佳答案

经过一些阅读,我发现 java 文本包对 RTF 文件类型的支持并不完整,当您使用 TRFEditorkit 写入或读取文件时,您会得到纯文本。

关于java - JTextpane 不会在文件中保存属性文本和图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55465948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com