read file from external storage

限于喜欢 提交于 2019-11-27 21:49:01

问题


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


回答1:


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

final File file = new File(Environment.getExternalStorageDirectory()
                          .getAbsolutePath(), filename);



回答2:


You can just do this:

File f = new File(Environment.getExternalStorageDirectory()
                            .getAbsolutePath() + File.separator + fileName);



回答3:


Better still:

final File file = new File(Environment.getExternalStorageDirectory(), filename);



回答4:


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");


来源:https://stackoverflow.com/questions/8370665/read-file-from-external-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!