when i was inserting the bitmap image to files directory, it showing file not found exception and it is showing Is a Directory.
Here is my code:
Use file.createNewFile()
if you want to make a file and not a directory.
You may also need to use mkDirs()
if the path doesn't exist either.
You are opening the directory itself for writing. This does not work. You need to specify a file within the directory, e.g.:
fos = new FileOutputStream(new File(mFolder, "myfile"));
File sdcard = Environment.getExternalStorageDirectory();
File dir = new File(sdcard.getAbsolutePath() + "/text/");
dir.mkdir();
File file = new File(dir, "sample.txt");
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
os.write(enterText.getText().toString().getBytes());
os.close();
}
catch (IOException e) {
e.printStackTrace();
}
you have to create file, before writing into stream.
File mFolder = new File(getFilesDir() + "/sample");
File imgFile = new File(mFolder.getAbsolutePath() + "/someimage.png");
if (!mFolder.exists()) {
mFolder.mkdir();
}
if (!imgFile.exists()) {
imgFile.createNewFile();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(imgFile);
bitmap.compress(Bitmap.CompressFormat.PNG,70, fos);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}