如何使用POI API使用相同的名称保存Doc文件

public class readDoc {
    public static void main( String[] args ) {
        String filesname = "Hello.doc";
        POIFSFileSystem fs = null;
        try {
            fs = new POIFSFileSystem(new FileInputStream(filesname;
            //Couldn't close the braces at the end as
            my site did not allow it to close
            HWPFDocument doc = new HWPFDocument(fs);
            WordExtractor we = new WordExtractor(doc);
            String[] paragraphs = we.getParagraphText();
            System.out.println( "Word Document has " +
            paragraphs.length + " paragraphs" );
            for( int i=0; i<paragraphs .length; i++ ) {
                System.out.println("Length:"+paragraphs[i].length());
            }
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}

最佳答案

FileOutputStream fos = new FileOutputStream(filesname);
doc.write(fos);
fos.close();


您也可以尝试写入POIFsFileSystem

FileOutputStream fos = new FileOutputStream(filesname);
fs.write(fos);
fos.close();

关于java - 如何使用POI API保存Word文档?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8484906/

10-10 14:36