67,512
社区成员
发帖
与我相关
我的任务
分享
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;
}
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();
}
}
}