从网上找了这个方法,可以写成功文档,但是文档内容会乱码,请大神赐教
String uContent = “<html><p><s] X Mpan><strong>标题&U h - S H Ult;/strong></span><br/></p><p>我想要3个<em>苹果</em>。</p></htm+ * M . bl>;
byte b[] = uContent.getBytes("utf-8");
ByteArrayInputStream bais = new ByteArrayInputStream(b);
//生成Word文档
POIFSFileSystem poifs = new POIFSFileSystem();
DirectoryEntry directory = poifs.E X P ? N _ cgetRoot();
DocumentED x $ k * # G cntry documentEntry = directory.c~ j 3 1 8 reateDocument("WordDocu_ 7 u C / ^ dment", bais);//生成word
FileOutputStream ostream = new FileOutputStream(WordPath);
poifs.writeFilesystem(ostream);//把文档写到指定位置
bais.close();
ostream.close();
这是文档乱码的样子
回答
byte b[] = uContent.getBytes("utf-8"); 换成gbk试试
发表评论