I need to save a camera image on Android. I used write permission on external storage in the manifest and I use this code
File dir = new File(Environment.getExternalStorageDirectory(), "Test"); if (!dir.exists() || !dir.isDirectory()) dir.mkdirs(); String path = dir.getAbsolutePath(); Log.d(TAG, path); //log show the path File file = new File(dir.getAbsolutePath() + "/Pic.jpg"); Log.d(TAG, file.getAbsolutePath()); //again path is shown here outStream = new FileOutputStream(file); outStream.write(bytes); outStream.close(); Log.d(TAG, "onPictureTaken - wrote bytes: " + bytes.length); //fail here } catch (FileNotFoundException e) { Log.d(TAG, "not done"); //error is here (this exception is thrown) } catch (IOException e) { Log.d(TAG, "not"); } finally { }
I also tried mkdir () instead of mkdirs () with the same result.
any idea what went wrong in the code?
thanks
source share