NSt*_*orm 2 java android unzip
首先,我搜索了很多次,并搜索了大量的Stackoverflow页面,但我无法得到任何工作.我想要做的是我有一个zip文件,其结构如下:
zipfile.zip
夹
Subfolder1
带有空格的子文件夹(大约100个,但不知道这些数量)
子子文件夹带空格
一些文件
SubSubFolderWithoutSpaces
还有一些文件
Subfolder2
带有空格的子文件夹(大约100个,但不知道这些数量)
子子文件夹带空格
一些文件
SubSubFolderWithoutSpaces
还有一些文件
Subfolder3
带有空格的子文件夹(大约100个,但不知道这些数量)
子子文件夹带空格
一些文件
SubSubFolderWithoutSpaces
还有一些文件
Subfolder4
带有空格的子文件夹(大约100个,但不知道这些数量)
子子文件夹带空格
一些文件
SubSubFolderWithoutSpaces
还有一些文件
我目前正在使用http://www.jondev.net/articles/Unzipping_Files_with_Android_%28Programmatically%29中的代码来尝试解压缩文件,但它所做的只是创建一个名为zipfile的目录,然后在其中有一个子目录在目录中没有任何内容的被称为文件夹,显然不应该发生.
任何帮助将非常感激.
更新:哦,如果你想知道我有WRITE_EXTERNAL_STORAGE_PERMISSION.
我希望这可以帮到你:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
参考:
android pico installer source
| 归档时间: |
|
| 查看次数: |
1943 次 |
| 最近记录: |