So here is my code:
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName,
".jpg",
storageDir
);
However, my application aborts the error when File.createTempFile:
java.io.IOException: open failed: ENOENT (No such file or directory).
From the documentation File:
Parameters:
prefix the prefix to the temp file name.
suffix the suffix to the temp file name.
directory the location to which the temp file is to be written, or null for the default location for temporary files, which is taken from the "java.io.tmpdir" system property. It may be necessary to set this property to an existing, writable directory for this method to work properly.
Returns:
the temporary file.
Throws:
IllegalArgumentException - if the length of prefix is less than 3.
IOException - if an error occurs when writing the file.
What are the chances of writing a temporary file unsuccessfully? Since I am pointing to external storage and an external SD card is connected to the device.
source
share