I am trying to write an image file to a shared gallery folder in a specific directory, but I continue to receive an error message that I cannot open the file because its directory.
So far, I have been next
//set the file path String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator + directory; File outputFile = new File(path,"testing.png"); outputFile.mkdirs(); FileOutputStream out = new FileOutputStream(outputFile); bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
Where directory is the name of the application. Thus, all photos saved by the application will go into this folder / directory, but I continue to receive an error
/storage/sdcard0/Pictures/appname/testing.png: open failed: EISDIR (Is a directory)
Even if I'm not trying to put it in a directory and pass the variable path as a file, for example
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
I do not get an error, however the photo is still not displayed in the gallery.
*** Answer The problem was that when I ran this code initially, it created a DIRECTORY named testing.png because I was unable to create the directory before creating the IN file in the directory. So the solution is to create a directory first and then write a separate file to it, for example
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString() + File.separator + directory;
Please note that you may need to log into your repository and manually delete the directory if you made the same mistake as me, starting with
source share