Fellow programmers.
Cuold you possibly take a look on this simple code frag and tell me what’s wrong here?
File dir = new File(Environment.getExternalStorageDirectory() + "/asteroids/modules");
File file = new File(Environment.getExternalStorageDirectory() + "/asteroids/modules/" + fileName);
if (!file.exists()) {
dir.mkdir();
file.createNewFile();
}
I keep geting ENOENT (No such file or directory) on file.createNewFile();
I just want to create a simple txt file nested in 2 subfolders on my SDcard…
The likely scenario is that the
asteroidsdirectory doesn’t exist, so you can’t create themodulesdirectory within it.Use
dir.mkdirs()to ensure that all parent directories also get created.