1
解壓縮文件,我想從SD卡使用下面的代碼從SD卡
public void unzip(String zipFilePath, String destDirectory, String filename) throws IOException {
File destDir = new File(destDirectory);
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
ZipEntry entry = zipIn.getNextEntry();
// iterates over entries in the zip file
while (entry != null) {
String filePath = destDirectory + File.separator + entry.getName();
if (!entry.isDirectory()) {
// if the entry is a file, extracts it
extractFile(zipIn, filePath);
} else {
// if the entry is a directory, make the directory ;
File dir = new File(filename);
dir.mkdir();
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
zipIn.close();
}
/**
* Extracts a zip entry (file entry)
* @param zipIn
* @param filePath
* @throws IOException
*/
private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
byte[] bytesIn = new byte[BUFFER_SIZE];
int read = 0;
while ((read = zipIn.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);
}
bos.close();
}
上面的代碼是給我的錯誤解壓縮的文件。下面是日誌
java.io.FileNotFoundException: /mnt/sdcard/unZipedFiles/myfile/tt/images.jpg: open failed: ENOENT (No such file or directory)
在這裏我ziped目錄,其中包含圖像/子目錄,然後我試圖解壓縮。
誰能告訴我原因
感謝
您是否創建了'/ mnt/sdcard/unZipedFiles/myfile/tt /'目錄? – CommonsWare 2015-03-25 11:04:06
ENOENT(沒有這樣的文件或目錄):看看你的文件是否存在 – 2015-03-25 11:05:45
你在清單文件中提到過嗎? –
Yogendra
2015-03-25 11:08:07