How to Check Internal and External Storage If Exist

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



Leave a reply



Submit