poi 生成本地word(读取流写入新文档doc)

import java.io.*;
import java.util.*;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.util.LittleEndian;

public class WordTest {
public WordTest() {
}

public static boolean writeWordFile(String path, String content) {
boolean w = false;
try {

// byte b[] = content.getBytes("ISO-8859-1");
byte b[] = content.getBytes();

ByteArrayInputStream bais = new ByteArrayInputStream(b);

POIFSFileSystem fs = new POIFSFileSystem();
DirectoryEntry directory = fs.getRoot();

//生成word
directory.createDocument("WordDocument", bais);

FileOutputStream ostream = new FileOutputStream(path);

fs.writeFilesystem(ostream);

bais.close();
ostream.close();

} catch (IOException e) {
e.printStackTrace();
}
return w;
}

public static void main(String[] args) {
boolean b = writeWordFile("E://AAAAAAAAAAAAAAAAA.doc",
"wori");
}
}

你可能感兴趣的:(java-第三方包(jxl,poi等))