0

Possible Duplicate:
Test if file exists

I have stored one file in /files folder of my android app internal file system. I want to check whether it is stored there or not programatically.How i can check that?Please help me.

File file = getBaseContext().getFileStreamPath("Android.mk"); if(file.exists()) { Toast.makeText(this,"Android.mk exist", Toast.LENGTH_LONG).show(); }

Thanks in advance.

Community
  • 1
  • 1
user1662334
  • 659
  • 2
  • 9
  • 21

1 Answers1

3

If I write a file in the internal storage like described in the Android dev-tut (Link) to my applications private storage, Iam able to verify with you code that the file has been written successfully!

So the verification code should be all right. Maybe the way you are writing the file is wrong. Here is my code snippet:

String FILENAME = "Android.mk";
String string = "hello world";

FileOutputStream fos = openFileOutput(FILENAME, getBaseContext().MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

File file = getBaseContext().getFileStreamPath("Android.mk");
if (file.exists()) {
    Toast.makeText(this, "Android.mk exist", Toast.LENGTH_LONG).show();
}
Lars
  • 1,013
  • 8
  • 19