如何使用编码的Docx?(解压缩)

时间:2017-08-28 17:34:07

标签: java base64 docx unzip

HI  所以我的代码就像这样,我得到一个docx和一个文件夹来放置解压缩文件,

String templateLocation = "//path"; //this is where the document is located 
String AUX = "//path";   //this is a aux folder that's get the unzip files
unzip(new File(templateLocation), new File(AUX));

并且方法解压缩是

private static void unzip(File zipfile, File directory) throws IOException {

    ZipFile zfile = new ZipFile(zipfile);
    Enumeration<? extends ZipEntry> entries = zfile.entries();

    while (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();
      File file = new File(directory, entry.getName());
      if (entry.isDirectory()) {
        file.mkdirs();
      } 
      else {
        file.getParentFile().mkdirs();
        InputStream in = zfile.getInputStream(entry);
        try {
          copy(in, file);
        } 
        finally {
          in.close();
        }
      }
    }
  } 

问题是我需要使用Base64中的外部docx 但怎么样? 尝试这个

     String wordx = "DocxInBase64";
     byte[] dataFileWord = java.util.Base64.getDecoder().decode(wordx);
     String dataw = new String(dataFileWord,StandardCharsets.UTF_8);

但我得到了一些看起来像腐败的东西

PKXsgl}&#39; _br;曲@〜HWX = 4pv {10-30&#39; M,bwiO0E]}?`X ...

任何想法一开始?   提前致谢

1 个答案:

答案 0 :(得分:0)

您可以使用Apache POI来解析word文件。 http://poi.apache.org/document/index.html