apache poi ---如何使用java代码读取受密码保护的.doc文件?

时间:2016-03-09 13:48:46

标签: apache-poi

如何使用java代码读取受密码保护的.doc文件?

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
public class MsFileReader 
{
    public static void readDocFile(String fileName) 
    {

       try 
        {
              File file = new File(fileName);
              InputStream fis = new FileInputStream(file);
              HWPFDocument doc = new HWPFDocument(fis);
              WordExtractor we = new WordExtractor(doc);
              String[] paragraphs = we.getParagraphText();
              System.out.println("Total no of paragraph "+paragraphs.length);
              for (String para : paragraphs) 
              {
                     System.out.println(para.toString());
              }

             fis.close();
         } catch (Exception e) 
         {
              e.printStackTrace();
         }
    }

    public static void main(String[] args) 
    {
        //Test.doc is password encrypted file
        //after running this code it throws exception
        //EncryptedDocumentException
        readDocFile("C:\\Test.doc");
    }
}

我希望java代码读取密码加密的.doc文件。 我在HWPFDocument doc = new HWPFDocument(fis);得到EncryptedDocumentException;

0 个答案:

没有答案
相关问题