Code Bye

java读取doc文件内容的问题

小弟是用poi读取doc的
public static String docString(String filePath) {
		File file = new File(filePath);
		String result = "";
		try {
			FileInputStream fis = new FileInputStream(file);
			HWPFDocument doc = new HWPFDocument(fis);
			Range rang = doc.getRange();
			result += rang.text();
			fis.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

但是读取出来的内容会这样的 TOC \o “1-3” \h \z \u HYPERLINK \l “_Toc440010147″一、一般要求  PAGEREF _Toc440010147 \h 4,带有TOC \o “1-3” \h \z \u HYPERLINK \l “_Toc440010147″这些本人不需要的东西 问一下是本人读取的方法不对吗?或该怎么去掉这些多余的字符

解决方案

50

本人写的一个例子,读取word文档没有问题。
public class ReadWord {
	public static void main(String[] args) {
		File doc1 = new File("doc/2012年秋季期末试题.doc");
		if (doc1.exists()) {
			System.out.println("文件存在!");
		} else {
			System.out.println("文件不存在!");
		}

		try {
			InputStream is=new FileInputStream(doc1);
			WordExtractor we=new WordExtractor(is);
			System.out.println(we.getText());
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明java读取doc文件内容的问题