简体   繁体   English

FileNotFoundException:/ storage / emulated / 0 / Android

[英]FileNotFoundException: /storage/emulated/0/Android

I try this file writer/reader code segment for test: 我尝试此文件编写器/读取器代码段进行测试:

File file = new File(Environment.getExternalStorageDirectory(), "LM/lm_lisdat_01.txt");
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(("test").getBytes());
outputStream.close();

File file = new File(getExternalFilesDir(null), "LM/lm_lisdat_01.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

In the 4. row i got this error message below but the "lm_lisdat_01.txt" file was created in LM directory: 在4.行中,我在下面收到此错误消息,但是在LM目录中创建了“ lm_lisdat_01.txt”文件:

java.io.FileNotFoundException: /storage/emulated/0/Android/data/hu.abisoft.lm/files/LM/lm_lisdat_01.txt: open failed: ENOENT (No such file or directory) java.io.FileNotFoundException:/storage/emulated/0/Android/data/hu.abisoft.lm/files/LM/lm_lisdat_01.txt:打开失败:ENOENT(没有此类文件或目录)

Can help anyone for answer this (i think simple) question? 可以帮助任何人回答这个(我认为很简单)的问题吗? I'm newby in Android. 我是Android的newby。 Thank you! 谢谢!

You are creating the file in one directory and trying to open it for input in another. 您正在一个目录中创建文件,然后尝试将其打开以在另一目录中输入。

Environment.getExternalStorageDirectory() is /storage/emulated/0 Environment.getExternalStorageDirectory()是/ storage / emulated / 0

getExternalFilesDir(null) is /storage/emulated/0/Android/data/hu.abisoft.lm/files getExternalFilesDir(null)是/storage/emulated/0/Android/data/hu.abisoft.lm/files

Use the same directory for file creation and input. 使用相同的目录进行文件创建和输入。

Please see changes. 请查看更改。 Your path was wrong. 你的路错了。

And also check whether file exists or not. 并检查文件是否存在。

    File file = new File(Environment.getExternalStorageDirectory(), "LM/lm_lisdat_01.txt");
    FileOutputStream outputStream = new FileOutputStream(file);
    outputStream.write(("test").getBytes());
    outputStream.close();

    File file = new File(Environment.getExternalStorageDirectory(), "LM/lm_lisdat_01.txt");//changes here
if(file.exists())
   { 

  BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
   }

With sdk, you can't write to the root of internal storage. 使用sdk,您无法写入内部存储的根目录。 This cause your error. 这会导致您的错误。 Edit : 编辑:

Based on your code, to use internal storage with sdk: 根据您的代码,将内部存储与sdk结合使用:

final File dir = new File(context.getFilesDir() + "/nfs/guille/groce/users/nicholsk/workspace3/SQLTest");
dir.mkdirs(); //create folders where write files
final File file = new File(dir, "BlockForTest.txt");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 FileNotFoundException:/ storage / emulated / 0 / Download /-Android Oreo - FileNotFoundException: /storage/emulated/0/Download/ - Android Oreo FileNotFoundException:/ storage / emulated / 0 / Pictures / - FileNotFoundException: /storage/emulated/0/Pictures/ 访问存储在android中的/ storage / emulated / 0目录中的文件时出现FileNotFoundException - FileNotFoundException when accessing file stored at /storage/emulated/0 directory in android java.io.FileNotFoundException:/ storage / emulated / 0 / - java.io.FileNotFoundException: /storage/emulated/0/ Java android Java.io.FileNotFoundException:无内容提供者:/storage/emulated/0/Android/data - Java android Java.io.FileNotFoundException: No content provider: /storage/emulated/0/Android/data 模拟外部存储android - emulated external storage android android kotlin java.io.FileNotFoundException:/storage/emulated/0/number.txt:打开失败:EACCES(权限被拒绝) - android kotlin java.io.FileNotFoundException: /storage/emulated/0/number.txt: open failed: EACCES (Permission denied) Android - java.io.FileNotFoundException: /storage/emulated/0/Notes/File.txt: open failed: ENOENT (No such file or directory) - Android - java.io.FileNotFoundException: /storage/emulated/0/Notes/File.txt: open failed: ENOENT (No such file or directory) getBitmap: FileNotFoundException: file:/storage/emulated/0/DCIM/camera/IMG_20191029_101624.jpg(没有这样的文件或目录)(Android) - getBitmap: FileNotFoundException: file:/storage/emulated/0/DCIM/camera/IMG_20191029_101624.jpg (No such file or directory) (Android) java.io.FileNotFoundException:/storage/emulated/0/Android/data/MyApplication/MyFile.ics。 (没有这样的文件或目录)/ Android Studio / Ical4j - java.io.FileNotFoundException: /storage/emulated/0/Android/data/MyApplication/MyFile.ics. (No such file or directory) / Android Studio / Ical4j
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM