当前位置:编程学习 > JAVA >>

POI写出的Word文档有的能打开,有的打不开


代码:
 
//读取word
 FileInputStream in = new FileInputStream(file);
 HWPFDocument doc = new HWPFDocument(in);
 Range range = doc.getRange();
 String content = range.text();

//替换文本内容
 content = content.replaceAll("#[\u4e00-\u9fa5\\w\\.\\-\\+]*@", "{");
 content = content.replaceAll("#", "}");
 range.replaceText(range.text(),content);
 ByteArrayOutputStream ostream = new ByteArrayOutputStream();
 filePath = file.getAbsolutePath().substring(0,file.getAbsolutePath().substring(0,file.getAbsolutePath().lastIndexOf("\\")).lastIndexOf("\\")+1)+
 "Public_doc\\"+file.getName();
 File f = new File(filePath);
 if(f.exists()){
 f.delete();
 }
 f.createNewFile();
 FileOutputStream out = new FileOutputStream(f,true);
 doc.write(ostream);
 out.write(ostream.toByteArray());
 out.flush();
 ostream.close();
跟word文档的大小有关吗?
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,