"내부 저장소에"unzip "이라는 폴더를 만든 다음 파일을 내부 저장소"unzip folder "에 압축을 해제하려고합니다. 내가 뭘 잘못하고 있는지 확실하지 않아? 당신이 잘못하면 무엇이 좋을 지 설명해주십시오. 감사합니다내부 저장소의 폴더에 압축 해제
편집 : 문제는 폴더가 생성되고 파일이 압축 해제되지 않는 것입니다.
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();
}
}
글쎄, 어떤 것이 효과가 있는지 설명하고 싶을 수도 있습니다. 내가 한 번 보는 것은 File mydir = this.getDir ("unzip", Context.MODE_PRIVATE); // 내부 저장소에 폴더를 만듭니다. 실제로 디렉토리를 만들지는 않을 것입니다. –
그래, 그게 좋은 생각이야 롤 –