Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java搜索docx文件并将其解压缩到给定目录中?_Java_Xml_Xslt - Fatal编程技术网

如何使用java搜索docx文件并将其解压缩到给定目录中?

如何使用java搜索docx文件并将其解压缩到给定目录中?,java,xml,xslt,Java,Xml,Xslt,实际上,我将把.docx文件转换成.xhtml。所以我需要找到给定目录中的doc文件并解压缩它。从word文件中获取document.xml后,我需要使用一些xsl文件处理该文件,以获得最终结果为.xhtml //-------------------------Source-------------------------------------- simpleTransform(Source+"/"+"filename"+".xml", Source+"/01-

实际上,我将把.docx文件转换成.xhtml。所以我需要找到给定目录中的doc文件并解压缩它。从word文件中获取document.xml后,我需要使用一些xsl文件处理该文件,以获得最终结果为.xhtml

//-------------------------Source--------------------------------------               
simpleTransform(Source+"/"+"filename"+".xml", Source+"/01-W2H.xslt", Source+"/"+"out2.xml");
simpleTransform(Source+"/"+"out2.xml", Source+"/08-xmlns.xslt", Source+"/"+"out22.xml");
simpleTransform(Source+"/"+"out22.xml", Source+"/06-Heading.xslt", Source+"/"+"out3.xml");
simpleTransform(Source+"/"+"out222.xml", Source+"/02-FigureRef.xsl", Source+"/"+"out222.xml");
simpleTransform(Source+"/"+"out3", Source+"/03-Remove-Duplecate.xsl", Source+"/"+"OUT4.xml");
simpleTransform(Source+"/"+"out4.xml", Source+"/04-Return_XML_To_Position.xsl", Source+"/"+"OUT5.xml");
simpleTransform(Source+"/"+"out5.xml", Source+"/05-Final.xsl", Source+"/"+"filename"+".xhtml");       
simpleTransform(Source+"/com.apple.ibooks.display-options.xm", Source+"/07-Combine.xsl", Source+"/"+"del.txt");
simpleTransform(Source+"/"+"merged-html.xml", Source+"/08-xmlns.xslt", Source+"/"+"merged-html2.xml");
simpleTransform(Source+"/"+"merged-html2.xml", Source+"/09-OPF.xsl", Source+"/"+"del2.txt");
simpleTransform(Source+"/merged-html2.xml", Source+"/10-NCX.xsl", Source+"/del3.xml");
simpleTransform(Source+"/toc.ncx", Source+"/10-NCX2.xsl", Source+"/toc.ncx");
simpleTransform(Source+"/toc.ncx", Source+"/11-Heading.xslt", Source+"/toc.ncx");
simpleTransform(Source+"/toc.ncx", Source+"/11-idsequence.xsl",  Source+"/toc.ncx");          
simpleTransform(Source+"/merged-html2.xml", Source+"/12-Contents.xsl",  Source+"/contents.xhtml");
  • 对于按扩展名搜索文件,可以使用库:
  • 方法:

    FileUtils.iterateFiles(File directory, String[] extensions, boolean recursive)
    
  • 对于zip\unzip:
  • 阶级

    诸如此类:

    try(ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(fileInputStream)) {
        ZipArchiveEntry zipEntry;
    
        while ((zipEntry = zipArchiveInputStream.getNextZipEntry()) != null){
            String fileName = zipEntry.getName();
    
            final File file = new File(fileName);
    
            FileUtil.createMissingParentDirectories(file);
    
            try(FileOutputStream fileOutputStream = new FileOutputStream(file.getAbsolutePath())) {(file.read.buffer)
                try(BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream, 1024)) {
                    int n = 0;
    
                    byte[] content = new byte[1024];
    
                    while ((n = zipArchiveInputStream.read(content)) != -1) {
                        fileOutputStream.write(content, 0, n);
                    }
    
                    bos.flush();
                    }
                }
            }
        }
    }
    

    您已经尝试了什么?FilenameFilter filefilter=new FilenameFilter(){public boolean accept(File projectPathF,String name){return name.endsWith(“.doc”)| | name.endsWith(“.docx”)};File[]linkFiles=projectPathF.listFiles(文件过滤器);这是解压的代码示例(从我的一个项目中提取并清理)