2015-01-21 139 views
2

我想从zip文件中删除文件,而无需在android中进行解压缩。我第一次使用下面的代码如何在Android中删除zip文件中的文件

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工作做到了与Java,在logcat的

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

Isearched发生了用于分辨率错误并得到了一个暗示,Android没有'java.nio.file.Paths'这个东西, 我正在寻找一个替代解决方案可以zip4j或TrueZip将在这里做诡计,

我试过用truezip,b使用此代码

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
+0

我猜你为TrueZIP下载了错误的JAR文件。请查看https://truezip.java.net/kick-start/no-maven.html。另请注意,TrueZIP处于维护模式。对于新项目,您应该使用TrueVFS。相应的页面是https://truevfs.java.net/kick-start/no-maven.html。 – 2015-01-22 12:13:12

回答

0

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

确保您包含所有正确的依赖关系。我假设你使用的摇篮,所以依赖会是这个样子:

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

我处理了类似的错误在使用Maven Java项目进口的依赖。试试这些东西并提供你的Java版本。

相关问题