
word
然后写个类:Javapublic class word { // 读取纯文本的word文件 public String readword(String doc) throws Exception { String context = null; wordExtractor extractor = null; try { FileInputStream in = new FileInputStream(new File(doc)); extractor = new wordExtractor(in); context = extractor.getText(); } catch (Exception e) { e.printStackTrace(); } return context; } // 写入word文档 public boolean writeword(String path, String content) throws Exception { boolean w = false; try { byte b = content.getBytes(); FileOutputStream fs = new FileOutputStream(path); HWPFOutputStream hos = new HWPFOutputStream(fs); hos.write(b, 0, b.length); hos.close(); w = true; } catch (Exception e) { e.printStackTrace(); } return w; } // 主方法测试一下 public static void mAIn(String args) { word word = new word(); try { String text = word.readword(D:\workspace\MyUntil\t.doc); word.writeword(D:\workspace\MyUntil\d.doc, text); } catch (Exception e) { e.printStackTrace(); } }}
代码大概就这样,你可以照着改路径啥的跑一下试试看。要是还有啥问题欢迎继续问,别光问不试哈~
Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号