Java 如何在android中删除zip文件中的文件

Java 如何在android中删除zip文件中的文件,java,android,zip,truezip,Java,Android,Zip,Truezip,我想从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);

我想从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.path

我在中寻求解决方案,并得到一个提示,android没有“java.nio.file.path”这个东西, 我正在寻找另一种解决方案,zip4j或TrueZip可以解决这个问题

我尝试使用truezip,但使用了以下代码

TFile archive = new TFile("archive.zip");
for (String member : archive.list())
 System.out.println(member);
但是archive.list()返回null,但是archive.length返回正确的文件大小

我不知道我在这里做错了什么,我在一个罐子里下载了truezip 7.7。但是当我给这个
import de.schlichtherle.io.File


请帮助

您使用的是什么版本的Java

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

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

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

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

我猜你为TrueZIP下载了错误的JAR文件。请看一看。另外,请注意TrueZIP处于维护模式。对于新项目,应使用TrueVFS。相关页面为。