I'm trying to figure out how to find if a file exists in Internal Storage. My current code looks like this however when I run it in my emulator I get file not found. I believe the path of the file I am looking for is located in /storage/emulated/0/Download/filename.txt. I can see the file through the folders manager but my code does not access it. I'm not sure what I am doing wrong.
public void onClick(View v) {
//tvRETURN.setText("File not found");
final EditText etFilename = (EditText) findViewById(R.id.ET_filename);
final String filename = etFilename.getText().toString();
boolean fileFound = isFilePresent(filename);
if(!fileFound){
tvRETURN.setText("File not found");
} else{
tvRETURN.setText("File found");
}
/* try {
FileInputStream fileIn = openFileInput(filename);
} catch (Exception e){
tvRETURN.setText("File not found");
e.printStackTrace();
}*/
}
});
}
public boolean isFilePresent(String fileName) {
String path = getBaseContext().getFilesDir().getAbsolutePath() + "/" + fileName;
File file = new File(path);
return file.exists();
}