如何在Java简单的实现各种文档格式的转换

lionhero 2001-04-08 03:56:00
例如 txt<=>rtf,rtf<=>html,txt<=>xml,txt<=>doc

...全文
92 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
v不吃v你 2001-04-08
  • 打赏
  • 举报
回复
//我想先从。DOC中读入,在写入TXT中。
//下面的程序没有调试过。
//你可以自己调试以下。
//希望对你有用。

File myfile = new File("c:\\testing.doc");
try
{
myrfile= new RandomAccessFile(myfile,"r");

String fileContent, asciiContent;
Character lineContent;
//read the text form file content line by line while((fileContent = myrfile.readLine())!=null)
{
while((lineContent=fileContent.readChar())!=null){
//now check each character whether it is printable or not
if (lineContent.isPrintable.. =="\n")//check for the syntax
System.out.print(lineContent);
}

}// end of while

//close the file after use
myrfile.close();
}
v不吃v你 2001-04-08
  • 打赏
  • 举报
回复
import javax.swing.* ;
import javax.swing.text.* ;
import javax.swing.text.rtf.* ;
import java.io.* ;

public class RTFExample extends JFrame
{
RTFEditorKit editorKit = new RTFEditorKit() ;
JTextPane textPane = new JTextPane() ;

public static void main(String[] args)
{
RTFExample rtfExample = new RTFExample() ;
rtfExample.setSize(400,400) ;
rtfExample.setVisible(true) ;
}

public RTFExample()
{
super() ;
getContentPane().add(textPane) ;
textPane.setEditorKit(editorKit) ;
try
{
editorKit.read(new FileInputStream("c:\\test.rtf"), textPane.getDocument(),0) ;
} catch (Exception e) { System.out.println(e) ;}
}
}

lionhero 2001-04-08
  • 打赏
  • 举报
回复
简单实现即在java 类库中的专用的用于文档格式转换类
虎叔 2001-04-08
  • 打赏
  • 举报
回复
简单的实现 什么意思?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧