views:

54

answers:

1

Hi! I have this code:

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.

+2  A: 

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

Tao
ok.. but what makes it locked? I am not using/opening it. By the way I am just using an emulator.
junmats
agreed, it wouldn't hurt to test if the file can be read with `canRead()` in addition of `exists()`
Joubarc
@Joubarc: I followed your suggestion and by putting canRead() condition, it results to false. Does it mean that it is locked? But why? I don't understand why my zip file is locked since I am not using it.
junmats
Maybe you can't read the file because of permission issues? It could have been written by another application with `MODE_PRIVATE`, for example. Could you try with another file on the sd card and see if there's a difference?
Joubarc