Question: I use the following code to check file availability 

```
    File f1=new File("/data/data/com.myfiledemo/files/settings.dat");
    if(f1.exists())
    textview.setText("File Exist");

```

If i use the following code it's not responding

```
   File f1=new File("settings.dat");
   if(f1.exists())
   tv.setText("File Exist");

```

Here com.myfiledemo is my application package . I simply create the file like this 

```
   fileInputstream = openFileInput("settings.dat");  

```

why It's not responding for the second if condition.??Is it Wrong??

Answer: 
The second code snippet is not the correct way to use, If you insist on using a java.io.File object, it should be:

```
File f1=new File(context.getFilesDir(), "settings.dat");
if(f1.exists()) {
  tv.setText("File Exist");
}

```
If you create the file by using `openFileInput`, then this is the way to check whether the file exists or not:

```
FileInputStream input = null;
try{
    input = openFileInput("settings.dat");
}
catch(FileNotFoundException e){
    // the file does not exists
}

if( input != null ){
    tv.setText("File Exist");
}

```