10

I simply cannot find how to get one specified file from the external storage. I know that with getExternalStoragePublicDirectory(), you get the external storage directory but I can't get further. I need some kind of method where you have to give the name of the file and it returns the file. Thanx

Kat
  • 668
  • 2
  • 11
  • 24

4 Answers4

24

Better than using File.separator is this, which is standard Java:

final File file = new File(Environment.getExternalStorageDirectory()
                          .getAbsolutePath(), filename);
J. B. Rainsberger
  • 1,193
  • 9
  • 23
6

You can just do this:

File f = new File(Environment.getExternalStorageDirectory()
                            .getAbsolutePath() + File.separator + fileName);
Chris
  • 22,923
  • 4
  • 56
  • 50
3

Better still:

final File file = new File(Environment.getExternalStorageDirectory(), filename);
gisHermit
  • 121
  • 1
0

I also use getExternalStoragePublicDirectory() and everything goes well. My filename is "DE Disimpan"

File file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File filepath = new File(file,"DE Disimpan");