Test if file exists

Posted by klaus-vlad on Stack Overflow See other posts from Stack Overflow or by klaus-vlad
Published on 2010-05-07T06:33:10Z Indexed on 2010/05/07 6:38 UTC
Read the original article Hit count: 299

Filed under:

Hi,

I'm trying to open a file in android like this :

  try
   {
      FileInputStream fIn = context.openFileInput(FILE);
      DataInputStream in = new DataInputStream(fIn);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      if(in!=null)
          in.close();
   }
   catch(Exception e)
   {  }

, but in case the file does not exists a file not found exception is thrown . I'd like to know how could I test if the file exists before attempting to open it.

© Stack Overflow or respective owner

Related posts about android