[英]how can I access files in the internal storage's root directory?
我的设备没有SD卡,但是我可以在Windows资源管理器中访问“内部存储”文件,其中有一个“ tmp.txt”。
txt文件是通过Windows资源管理器粘贴的,现在我想读取该文件。 我的代码是:
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"tmp.txt");
StringBuilder text = new StringBuilder();
try {
InputStream in = new FileInputStream(file);
...
}
catch (IOException e) {
}
但是它不起作用,它在new FileInputStream(file);
之后捕获异常new FileInputStream(file);
,调试信息记录的文件位置实际上是"/storage/emulated/0/tmp.txt"
,因此找不到该文件。 然后,我尝试使用以下命令将文件放入下载目录:
File fileDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File file = new File(fileDir, "tmp.txt");
错误日志: 异常e:
这也不起作用,基本上它们是相同的问题。 我可以访问该目录中的文件吗?
请阅读以下内容:developer.android.com/guide/topics/data/data-storage您没有读取存储的权限,您放置的权限是用于位置服务的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.