I was trying to create a file to save pictures from the camera, it turns out that I can't create the file. But I really can't find the mistake. Can you have a look at it and give me some advice?
private File createImageFile(){ File imageFile=null; String stamp=new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File dir= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); String imageFileName="JPEG_"+stamp+"_"; try { imageFile=File.createTempFile(imageFileName,".jpg",dir); } catch (IOException e) { Log.d("YJW",e.getMessage()); } return imageFile; }
And I have added the permission.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
The method always gives such mistakes:
open failed: ENOENT (No such file or directory)
The ENOENT (No such file or directory) error may occur in application, If the application do not have storage permission. We suggest you to ensure whether the application has storage permission to read and write file in storage location. We have modified sample to provide storage permission at run time.
It's an abbreviation of Error NO ENTry (or Error NO ENTity), and can actually be used for more than files/directories. It's abbreviated because C compilers at the dawn of time didn't support more than 8 characters in symbols. Follow this answer to receive notifications.
log No such file or directory” the problem is most likely on the client side. In most cases, this simply indicates that the file or folder specified was a top-level item selected in the backup schedule and it did not exist at the time the backup ran.
The Pictures directory might not exist yet. It's not guaranteed to be there.
In the API documentation for getExternalStoragePublicDirectory()
, the code ensures the directory exists using mkdirs
:
File path = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES); File file = new File(path, "DemoPicture.jpg"); try { // Make sure the Pictures directory exists. path.mkdirs();
...so it may be as simple as adding that path.mkdirs()
to your existing code before you createTempFile
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With