junmats
junmats

Reputation: 1924

android problem in extracting zip file using ZipFile

try{

File f = new File("/data/cizip.zip");
 if(f.exists()){
   ZipFile zf = new ZipFile(f); //this always throws an error
/*some of my codes here*/
}
catch(IOException e){
   AlertDialog.Builder abd = new AlertDialog.Builder(this);
   abd.setMessage(e.getMessage());
   abd.show();
}

the line ZipFile zf = new ZipFile(f); always throws an error and I don't know why. And the error message is the file name ("/data/cizip.zip"), therefore I can't know the cause of the error. Can someone please tell me what causes this error? Thanks in advance.

Upvotes: 1

Views: 2309

Answers (2)

Mira Weller
Mira Weller

Reputation: 2432

Your app doesn't have read/write permissions directly in the /data/ directory. You should use either the correct subfolder "/data/data/your.program.package/" or just the "/sdcard/"

Upvotes: 0

Tao
Tao

Reputation: 14006

This is just a guess, but maybe the file is in use (locked)? I don't see anything obviously wrong with your code...

Upvotes: 2

Related Questions