Reputation: 794
I have created a file using FileOutputStream in my app,
fos = this.openFileOutput("foo.txt", Context.MODE_PRIVATE);
Now, I want to check if the file exists, using
File file = new File("foo.txt");
if (file.exists()) {
file.delete();
Log.d("tag", "im here");
}
If the file exists I want to delete it. But my code does not seem to reach "im here". Is my approach wrong? How can I correct it? Thanks
Upvotes: 1
Views: 21
Reputation: 15774
You need to specify the directory in which to look for the file. This can be achieved through the getFilesDir()
method.
File file = new File(getFilesDir(), "foo.txt");
if (file.exists()) {
file.delete();
Log.d("tag", "im here");
}
Upvotes: 3