[英]Unzip to folder in internal storage
I'm trying to create a folder in internal storage called "unzip" and then unzip a file into the internal storage "unzip folder". 我正在尝试在内部存储中创建一个名为“解压缩”的文件夹,然后将文件解压缩到内部存储“解压缩文件夹”中。 Not sure what i'm doing wrong?
不知道我在做什么错? If you could please explain what's wrong it'd be great!
如果您能解释什么地方不对,那就太好了! Thanks
谢谢
Edit: The issues is that I don't think the folder is being created and the file is also not being unzipped. 编辑:问题是我不认为正在创建文件夹,并且文件也没有解压缩。
public void send(View view) {
try {
File mydir = this.getDir("unzip", Context.MODE_PRIVATE);//create folder in internal storage
unzip(getFilesDir().getAbsolutePath(), job_no, getFilesDir() + "/unzip/");
} catch (IOException e) {
}
}
public void unzip(String filepath, String filename, String unzip_path) throws IOException {
InputStream is = new FileInputStream(filepath + filename);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
try {
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int count;
String filename_temp = ze.getName();
File fmd = new File(filepath + filename_temp);
if (!fmd.getParentFile().exists()) {
fmd.getParentFile().mkdirs();
}
FileOutputStream fout = new FileOutputStream(unzip_path + filename_temp);
while ((count = zis.read(buffer)) != -1) {
baos.write(buffer, 0, count);
byte[] bytes = baos.toByteArray();
fout.write(bytes);
baos.reset();
}
fout.close();
//}
}
} finally {
zis.close();
}
}
这将获得绝对存储设备。
final static String MEDIA_PATH = Environment.getExternalStorageDirectory().getPath() + "/";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.