I'm trying to create a simple image file on Android and have the two following methods: Creating the directory:
private void createThumbnailDir() {
File file = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
+ File.separator + "scouthouse",
"scouthouse_thumbnails");
this.getActivity().sendBroadcast(
new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
if (!file.mkdirs()) {
Log.d("file", "file not created");
}
}
Creating the file:
private File createNewThumbnailFile() {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss",
Locale.ENGLISH);
Date date = Calendar.getInstance().getTime();
File file = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
"scouthouse" + File.separator + "schouthouse_thumbnails" + File.separator
+ sdf.format(date) + ".jpg");
try {
if (file.createNewFile()) {
return file;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
When I create the file the following IOException is raised: java.io.IOException: ENOENT (No such file or directory)
But the directory does exist when I check the file manager on my phone.
Edit:
More about the error: stacktrace = null, so I only have the cause and the detailmessage, and they're both the same: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)