简体   繁体   English

TrueZip无法从存档中提取文件

[英]TrueZip unable to extract file from archive

I am creating a java app that will extract the embedded thumbnail inside of a Powerpoint (PPTX) document. 我正在创建一个Java应用程序,它将在Powerpoint(PPTX)文档中提取嵌入式缩略图。 Since pptx files are zip archives, I am trying to use TrueZip to get the thumbnail found inside of the archive. 由于pptx文件是zip存档,因此我尝试使用TrueZip来获取存档内的缩略图。 Unfortunately whenever I try running my application it throws an IOException stating that the file is missing C:\\Users\\test-user\\Desktop\\DocumentsTest\\Hello.pptx\\docProps\\thumbnail.jpeg (missing file) 不幸的是,每当我尝试运行我的应用程序时,它都会引发IOException,指出该文件丢失了C:\\Users\\test-user\\Desktop\\DocumentsTest\\Hello.pptx\\docProps\\thumbnail.jpeg (missing file)

Below is the code I use to get the thumbnail: 以下是我用来获取缩略图的代码:

public Boolean GetThumbPPTX(String inFile, String outFile)
{
    try 
    {
        TFile srcFile = new TFile(inFile, "docProps\\thumbnail.jpeg");
        TFile dstFile = new TFile(outFile);

        if(dstFile.exists())
            dstFile.delete();

        srcFile.toNonArchiveFile().cp_rp(dstFile);

        return dstFile.exists();

    } catch (IOException ex) {
        Logger.getLogger(DocumentThumbGenerator.class.getName()).log(Level.SEVERE, null, ex);
    }

    return false;
}

Where inFile is the absolute path of the pptx file and outFile is the path that the thumbnail will be copied to. 其中inFile是pptx文件的绝对路径, outFile是缩略图将复制到的路径。 I can verify that the archive does have a thumbnail inside of it at the same exact path. 我可以验证存档中是否确实有缩略图位于相同的确切路径。

Can someone help please? 有人可以帮忙吗?

I just found the answer. 我才找到答案。 It seems I did not have the Zip driver configured correctly. 似乎我没有正确配置Zip驱动程序。 I added this to my class constructor and it all works now: 我将此添加到我的类构造函数中,并且现在都可以使用:

TConfig.get().setArchiveDetector(new TArchiveDetector(
            TArchiveDetector.NULL,
            new Object[][] {                
                { "zip|pptx", new ZipDriver(IOPoolLocator.SINGLETON)},
            }));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM