Currently i need access to 20 files. Sometimes it works perfectly. But sometimes (lets say 1 out of 3) it gives me: open failed: ENOENT (No such file or directory)
This happens than only to some of the directories, its completely random (it can be just 1 directory which cant be opened or 10, which dir is also random). The dirs dont change (the name, path or whatever).
I get access through a loop of the file entries in a dir (/storage/emulated/0/Altlasten/Projekte/...).
When the error occurs, the folder isnt a folder and doesnt exist, but the string representation is correct. The log output:
jsonFilePath: loadProjects: /storage/emulated/0/Altlasten/Projekte/2020_4_30_4er/Json/Projekt.json
Folder content: Folder name: 2020_4_30_4er; isDirectory: false; isFile: false; toString(): /storage/emulated/0/Altlasten/Projekte/2020_4_30_4er; exists: false
Folder content: Json File name: Projekt.json; isDirectory: false; isFile: false; toString(): /storage/emulated/0/Altlasten/Projekte/2020_4_30_4er/Json/Projekt.json; exists: false
W System.err: /storage/emulated/0/Altlasten/Projekte/2020_4_30_4er/Json/Projekt.json: open failed: ENOENT (No such file or directory)
My code to get access to the files/directories:
//Constants
public static final String JSON_DIR = "Json"
public static final String JSON_FILE = "Projekt.json"
//loop to access files
for (final File fileEntry : folder.listFiles()) {
try {
Log.i("Folder content",
"Folder name: " + fileEntry.getName()
+ "; isDirectory: " + fileEntry.isDirectory()
+ "; isFile: " + fileEntry.isFile()
+ "; toString(): " + fileEntry.toString()
+ "; exists: " + fileEntry.exists());
String jsonPath = fileEntry.getAbsolutePath() + File.separator + JSON_DIR + File.separator + JSON_FILE;
Log.i("jsonFilePath", "loadProjects: " + jsonPath);
File json = new File(jsonPath);
Log.i("Folder content",
"Json File name: " + json.getName()
+ "; isDirectory: " + json.isDirectory()
+ "; isFile: " + json.isFile()
+ "; toString(): " + json.toString()
+ "; exists: " + json.exists());
//do some stuff
} catch (Exception e) {
e.printStackTrace();
}
}