问题描述
- 这个poi把String写入word文档后,打开文档就报“打开文件错误”,求高人解决下
- import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class writeWord{
public static void main(String[] args) throws IOException{
byte[] a=new String(""看见了!"").getBytes(""GBK"");
ByteArrayInputStream bs = new ByteArrayInputStream(a);
POIFSFileSystem fs = new POIFSFileSystem();
///////////////////////////////////
DirectoryEntry directory = fs.getRoot();
DocumentEntry de = directory.createDocument(""WordDocument"" bs);
//以上两句代码不能省略,否则输出的是乱码
FileOutputStream fos = new FileOutputStream(""D:text111.doc"");
fs.writeFilesystem(fos);
bs.close();
//fos.flush();
fos.close();
System.out.println(""操作成功!"");
}}