Android - java.io.FileNotFoundException

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 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();
}