使用java读取word文档中的内容。帮帮举个了例子。 谢谢大家帮助。
展开全部
第一步:下载tm-extractors-0.4.jar下载地址:http://download.csdn.net/download/zcq87642231/1060382并把它放到你的classpath路径下面。第二步:简单的程序.(WordReader .java) import java.io.File;
import java.io.FileInputStream;
import org.textmining.text.extraction.WordExtractor;
public class WordReader {
public static String readDoc(String doc) throws Exception {
// 创建输入流读取doc文件
FileInputStream in = new FileInputStream(new File(doc));
WordExtractor extractor = null;
String text = null;
// 创建WordExtractor
extractor = new WordExtractor();
// 对doc文件进行提取
text = extractor.extractText(in);
return text;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
//读取文件
String text = WordReader.readDoc("D:/tt/tt.doc");
//得到数据后打印出来(也可用一个流写到txt文件中)
System.out.println(text);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
import java.io.FileInputStream;
import org.textmining.text.extraction.WordExtractor;
public class WordReader {
public static String readDoc(String doc) throws Exception {
// 创建输入流读取doc文件
FileInputStream in = new FileInputStream(new File(doc));
WordExtractor extractor = null;
String text = null;
// 创建WordExtractor
extractor = new WordExtractor();
// 对doc文件进行提取
text = extractor.extractText(in);
return text;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
//读取文件
String text = WordReader.readDoc("D:/tt/tt.doc");
//得到数据后打印出来(也可用一个流写到txt文件中)
System.out.println(text);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用流就可以读呀
String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
FileInputStream fis = null; FileOutputStream fos = null;
fis = new FileInputStream("e:/topo.svg"); fos = new FileOutputStream("e:/a.txt");
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(fis));
StringBuffer sb = new StringBuffer();
String str = null;
while ((str = bufferReader.readLine()) != null) {
sb.append(str + lineSeparator);
}
OutputStreamWriter writer = new OutputStreamWriter(fos);
writer.write(sb.toString());
writer.flush();
writer.close();
String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
FileInputStream fis = null; FileOutputStream fos = null;
fis = new FileInputStream("e:/topo.svg"); fos = new FileOutputStream("e:/a.txt");
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(fis));
StringBuffer sb = new StringBuffer();
String str = null;
while ((str = bufferReader.readLine()) != null) {
sb.append(str + lineSeparator);
}
OutputStreamWriter writer = new OutputStreamWriter(fos);
writer.write(sb.toString());
writer.flush();
writer.close();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询