My device has no SD card, but I can access the files of "Internal storage" in Windows explorer, in which there is a "tmp.txt".
The txt file was pasted via Windows explorer, now I want to read this file. My codes are:
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"tmp.txt");
StringBuilder text = new StringBuilder();
try {
InputStream in = new FileInputStream(file);
...
}
catch (IOException e) {
}
But it's not working, it step to catch exception after new FileInputStream(file);
, the debug information logs the file location actually is "/storage/emulated/0/tmp.txt"
, so it couldn't find the file. Then I tried put the file in the Download directory using:
File fileDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(fileDir, "tmp.txt");
error log: exception e:
It's not working either, basically they are the same problem. Can I access files in this directory?
请阅读以下内容:developer.android.com/guide/topics/data/data-storage您没有读取存储的权限,您放置的权限是用于位置服务的。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.