0

I am trying to access a file placed in my remove able memory card. What I am using is

File f=new File("/mnt/sdcard/CAPP/");              // f.exists() returns True 
File f=new File("/mnt/sdcard/CAPP/myfile.apk");    // f.exists() returns False

Any idea why its happening so ? Although myfile.apk is placed in CAPP folder. Thanks in advance.

Ali Akram
  • 199
  • 4
  • 12

2 Answers2

0

Please try this...

  String getFile = Environment.getExternalStorageDirectory().toString() + "folder name" + fileName;
            File file = new File(getFile );
Vikas singh
  • 3,461
  • 3
  • 14
  • 28
  • `Environment.getExternalStorageDirectory()` means we are accessing phone's external storage its not accessing remove able external storage. – Ali Akram Nov 22 '17 at 07:12
  • Please go through this link https://stackoverflow.com/questions/5694933/find-an-external-sd-card-location/5695129#5695129 – Vikas singh Nov 22 '17 at 07:32
0
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path/to/the/file/inside/the/myfile.apk");
Anand Jain
  • 2,365
  • 7
  • 40
  • 66
  • `Environment.getExternalStorageDirectory()` means we are accessing phone's external storage its not accessing remove able external storage. – Ali Akram Nov 22 '17 at 07:11
  • `Environment.getExternalStorageDirectory()` it means if device has any external storage it return his directory otherwise return internal storage directory. – Anand Jain Nov 22 '17 at 07:15