Java读取word文档

来源:互联网 发布:2017院士 知乎 编辑:程序博客网 时间:2024/06/10 06:23

下载相应的jar包(poi)




import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;


import org.apache.poi.hwpf.extractor.WordExtractor;




public class InputStream1 {


public static void main(String[] args) throws IOException {

String text = "";

File file = new File("D:\\111.doc");
InputStream is = new FileInputStream(file);
     WordExtractor word = new WordExtractor(is);
     
     text = word.getText();
     text = text.replaceAll("(\r\n|\r|\n|\n\r)", "<br/>");
     text = text.replaceAll(" ", "&nbsp");
     text = text.replaceAll("\t", "&nbsp&nbsp");
     System.out.println(text);
     
}
}

0 0