Android文件错误:打开失败:Enoent(没有此类文件或目录)
我会遇到错误:
Caused by: java.io.FileNotFoundException: /root/storage/FC73-12F9/AppList.txt: open failed: ENOENT (No such file or directory)
当我尝试在sndroid Studio上运行以下代码时:
if (it.resultCode == Activity.RESULT_OK) {
var selectedFile = it.data?.data
if (selectedFile !== null) {
Log.i("MainActivity", "Filename: ".plus(selectedFile?.path))
askForPermission(Manifest.permission.READ_EXTERNAL_STORAGE,0x4);
Log.i("MainActivity", File(selectedFile?.path).readText())
}
}
selectedfile?。代码>
我是Android开发的新手,有人可以指导我如何从给定的URI打开文件,selectedfile
是URI对象和selectedfile?。 filepath。
答案:
这有效
applicationContext.contentResolver.openInputStream(selectedFile)
I am getting as error:
Caused by: java.io.FileNotFoundException: /root/storage/FC73-12F9/AppList.txt: open failed: ENOENT (No such file or directory)
when I try to run the following code on sndroid studio:
if (it.resultCode == Activity.RESULT_OK) {
var selectedFile = it.data?.data
if (selectedFile !== null) {
Log.i("MainActivity", "Filename: ".plus(selectedFile?.path))
askForPermission(Manifest.permission.READ_EXTERNAL_STORAGE,0x4);
Log.i("MainActivity", File(selectedFile?.path).readText())
}
}
selectedFile?.path
is getting logged as /root/storage/FC73-12F9/AppList.txt
I am totally new to android development, can someone guide me on how to open a file from a given URI, selectedFile
is an URI object and selectedFile?.path
is the filepath.
Answer:
This worked
applicationContext.contentResolver.openInputStream(selectedFile)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论