How to check whether a file exists in (Internal/External storage) by using file name?
Probably, what you do wrong is using this.getFilesDir()
.
Instead, use Environment.getExternalStorageDirectory().toString()
for example, it's all dependant on where your file is.
Like I said before, debug it yourself, print (or present a toast) with the 'expected' file path, then verify it doesn't exist
Get directory of both internal storage and sd card if exist
There are thousands of links for tutorials, Android developer page is one of the many, below is the link ;
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
As far as I know, you can have access to your app internal dir and query whether sd card is mounted etc. But to get full access to device internal Dir? I doubt it because it would be breach of user's privacy. You even require user permission to query external storage
Can't check if file on sdcard exists
I think that problem is here:
getBaseContext()
where it is assigned to NULL
. You really don't need this line. You can simply achieve your goal with
String path = Environment.getExternalStorageDirectory().getPath() + "/ping.xml";
File f = new File(path);
if (f.exists()) {
// do your stuff
}
else {
// do your stuff
}
Update:
If you or someone else have Samsung Galaxy S3, please follow @Raghunandan's answer because in this case getExternalStorageDirectory()
returns internal memory.
how to check if file is available in internal storage
Let's say following is your file's path
String path=context.getFilesDir().getAbsolutePath()+"/filename";
File file = new File ( path );
if ( file.exists() )
{
// Toast File is exists
}
else
{
// Toast File is not exists
}
Related Topics
Android Sd Card Write Permission Using Saf (Storage Access Framework)
Android Calling Asynctask Right After an Another Finished
How to Automatically Uninstall Android App from Device Before Installing a New Version
Get Gps Location in a Broadcast Receiver/Or Service to Broadcast Receiver Data Transfer
Why Is Android Webview Refusing User Input
How to Take Multiple Photos Before Dismissing Camera Intent
How to Open Phones Gallery Through Code
Difference Between Finish() and System.Exit(0)
Android Opengl Es 2.0 Emulator
Android Simplecursoradapter Doesn't Update When Database Changes
Android. Scrolling 2 Listviews Together
How to Change the Color of the Tabs Indicator Text in Android
How to Change Background Color Popup Menu Android
Android - Add Textview to Layout When Button Is Pressed
Android Picasso Library, How to Add Authentication Headers