Android : Error in unzip folder in android

on Sunday, August 31, 2014


I want to copy zip file that includes images from asset to internal storage,And then unzip it. This is my code :



protected void copyFromAssetsToInternalStorage(String filename){
AssetManager assetManager = getAssets();

try {
InputStream input = assetManager.open(filename);
OutputStream output = openFileOutput(filename, Context.MODE_PRIVATE);

copyFile(input, output);

} catch (IOException e) {
e.printStackTrace();
}
}

private void unZipFile(String filename){
try {
ZipInputStream zipInputStream = new ZipInputStream(openFileInput(filename));
ZipEntry zipEntry;

while((zipEntry = zipInputStream.getNextEntry()) != null){
FileOutputStream zipOutputStream = openFileOutput(zipEntry.getName(), MODE_PRIVATE);

int length;
byte[] buffer = new byte[1024];

while((length = zipInputStream.read(buffer)) > 0){
zipOutputStream.write(buffer, 0, length);
}

zipOutputStream.close();
zipInputStream.closeEntry();
}
zipInputStream.close();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}


And i have this error : java.lang.IllegalArgumentException: File filename/ contains a path separator


What should i do?


0 comments:

Post a Comment