Java 在Android中解压包含子文件夹的文件夹
首先,我在谷歌上搜索了很多次,搜索了大量的Stackoverflow页面,但是我找不到任何有用的东西。我想做的是我有一个zip文件,其结构如下: zipfile.zip 文件夹 子文件夹1 带有空格的子文件夹(大约100个,但数量未知) 带有空格的子文件夹 一些文件 无空间子文件夹 还有几个文件 子文件夹2 带有空格的子文件夹(大约100个,但数量未知) 带有空格的子文件夹 一些文件 无空间子文件夹 还有几个文件 子文件夹3 带有空格的子文件夹(大约100个,但数量未知) 带有空格的子文件夹 一些文件 无空间子文件夹 还有几个文件 子文件夹4 带有空格的子文件夹(大约100个,但数量未知) 带有空格的子文件夹 一些文件 无空间子文件夹 还有几个文件 我目前正在使用中的代码尝试解压该文件,但它所做的只是创建一个名为zipfile的目录,然后在其中创建一个名为folder的子目录,该目录中没有任何明显不应该发生的事情 任何帮助都将不胜感激 更新:Java 在Android中解压包含子文件夹的文件夹,java,android,unzip,Java,Android,Unzip,首先,我在谷歌上搜索了很多次,搜索了大量的Stackoverflow页面,但是我找不到任何有用的东西。我想做的是我有一个zip文件,其结构如下: zipfile.zip 文件夹 子文件夹1 带有空格的子文件夹(大约100个,但数量未知) 带有空格的子文件夹 一些文件 无空间子文件夹 还有几个文件 子文件夹2 带有空格的子文件夹(大约100个,但数量未知) 带有空格的子文件夹 一些文件 无空间子文件夹 还有几个文件 子文件夹3 带有空格的子文件夹(大约100个,但数量未知) 带有空格的子文件夹 一
哦,如果您想知道我是否有写入外部存储权限。我希望这能帮助您:
private boolean unzipPack(InputStream stream) {
FileOutputStream out;
byte buf[] = new byte[16384];
try {
ZipInputStream zis = new ZipInputStream(stream);
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
if (entry.isDirectory()) {
File newDir = new File(rootDirectory + entry.getName());
newDir.mkdir();
} else {
String name = entry.getName();
File outputFile = new File(rootDirectory + name);
String outputPath = outputFile.getCanonicalPath();
name = outputPath
.substring(outputPath.lastIndexOf("/") + 1);
outputPath = outputPath.substring(0, outputPath
.lastIndexOf("/"));
File outputDir = new File(outputPath);
outputDir.mkdirs();
outputFile = new File(outputPath, name);
outputFile.createNewFile();
out = new FileOutputStream(outputFile);
int numread = 0;
do {
numread = zis.read(buf);
if (numread <= 0) {
break;
} else {
out.write(buf, 0, numread);
}
} while (true);
out.close();
}
entry = zis.getNextEntry();
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
private boolean解压包(InputStream){
文件输出流输出;
字节buf[]=新字节[16384];
试一试{
ZipInputStream zis=新的ZipInputStream(流);
ZipEntry entry=zis.getNextEntry();
while(条目!=null){
if(entry.isDirectory()){
File newDir=新文件(rootDirectory+entry.getName());
newDir.mkdir();
}否则{
String name=entry.getName();
File outputFile=新文件(根目录+名称);
字符串outputPath=outputFile.getCanonicalPath();
名称=输出路径
.substring(outputPath.lastIndexOf(“/”)+1);
outputPath=outputPath.substring(0,outputPath
.lastIndexOf(“/”);
File outputDir=新文件(outputPath);
outputDir.mkdirs();
outputFile=新文件(outputPath,名称);
outputFile.createNewFile();
out=新文件outputstream(outputFile);
int numread=0;
做{
numread=zis.read(buf);
如果(numread@NStorm),您有什么问题?