-2

I have a variable that just states outright:

File file = new File("/Extsdcard")

Am I foolish enough to think all android devices mount an external devices in this wording?

or should I be using Environment.getExternalStorageDirectory().getAbsolutePath();

My application searches through the first three folder layers so this is quite important to the functionality.

user1477834
  • 65
  • 1
  • 1
  • 9

2 Answers2

0
String path = Environment.getExternalStorageDirectory().toString()+"/YourDirectory";
 Log.d("Files", "enter code herePath: " + path);
 File directory = new File(path);
 File[] files = directory.listFiles();
 //It gives you list of all directoris/files list
 Log.d("Files", "Size: "+ files.length);
 for (int i = 0; i < 3; i++)
 {
     Log.d("Files", "FileName:" + files[i].getName());
 }
Raghabraj
  • 26
  • 1
  • that's not answering the question, is the standard "/yourdirectory" name "/EXTSDcard" across devices, is that how its titled when mounted by the device? – user1477834 Jun 29 '17 at 10:31
0

Environment.getExternalStorageDirectory() gets the top level of the external drive.

user1477834
  • 65
  • 1
  • 1
  • 9
  • It returns the root directory for [external storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). Few people would refer to this as an "external drive" or "external device", and it should never be `/Extsdcard`. All of those things tend to refer to [removable storage](https://commonsware.com/blog/2014/04/09/storage-situation-removable-storage.html), which is something separate. – CommonsWare Jun 29 '17 at 11:00