Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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)

Can help anyone for answer this (i think simple) question? I'm newby in Android. Thank you!

like image 807
Abigail La'Fay Avatar asked Mar 16 '26 08:03

Abigail La'Fay


1 Answers

You are creating the file in one directory and trying to open it for input in another.

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

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

Use the same directory for file creation and input.

like image 70
Bob Snyder Avatar answered Mar 17 '26 22:03

Bob Snyder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!