2

我想从 zip 文件中删除一个文件而不在 android 中提取它。我首先使用以下代码使用 java

Path zipFilePath = Paths.get(filePaths); //gave the path of the zip with zip file name
try( FileSystem fs = FileSystems.newFileSystem(zipFilePath, null) ){
    Path pathInZipfile = fs.getPath(reVsl3); //reVsl3 String which holds the name of the file to be deleted in  the zip file
  zipDelLoc=reVsl3; //just assigning it for future use
        System.out.println("About to delete an entry from ZIP File" + pathInZipfile.toUri() ); 
        // Execute Delete 
        Files.delete(pathInZipfile);
        System.out.println("File successfully deleted"); 
}
 catch (IOException e) {
     System.out.println(e+"Error here?");
}

这在netbeans中运行良好,但在ADT中不起作用,logcat中出现错误

java.lang.NoClassDefFoundError: java.nio.file.Paths

我搜索了一个解决方案,并得到一个提示,android没有'java.nio.file.Paths'这个东西,我正在寻找一个替代解决方案,zip4j或TrueZip可以在这里解决问题,

我尝试使用 truezip,但使用此代码

TFile archive = new TFile("archive.zip");
for (String member : archive.list())
 System.out.println(member);

但archive.list() 返回null,但archive.length 返回其正确的文件大小。

我不知道我在这里做错了什么,我在一个 jar 中下载了 truezip 7.7。但是当我给出这个时我得到了一个错误import de.schlichtherle.io.File

请帮忙

4

1 回答 1

0

您使用的是什么版本的 Java?

仔细检查您的导入。它应该类似于de.schlichtherle.truezip.nio.file.TPath;使用 TrueZip 时,您需要导入 java.nio.paths,即使您不使用它,而是使用 truezip 的路径风格。

确保包含所有正确的依赖项。我假设您使用的是 Gradle,所以依赖项看起来像这样:

'de.schlichtherle.truezip:truezip-file:7.7.9'

我使用 Maven 在 Java 项目中导入依赖项时处理了类似的错误。尝试这些事情并提供您的 Java 版本。

于 2015-07-29T14:31:45.520 回答