title: Take picture with camera intent and save to file
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8588838/android-camera-save-image-into-a-new-folder-in-sd-card">Android Camera - Save image into a new folder in SD Card</a>  </p>
  </blockquote>
  
  
  
  <p>i'm trying to take picture and save it to a file. The problem cames i'm trying to save the bitmap to a file. Here is my code:</p>
  
  <pre><code>private void takePic() {
      Intent cameraIntent = new Intent(
              android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
      startActivityForResult(cameraIntent, 2);
  
  
  }
  
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == 2) {
              Bitmap photo = (Bitmap) data.getExtras().get("data");
              ImageView test = (ImageView) findViewById(R.id.test);
              test.setImageBitmap(photo);
  
              try {
                  FileOutputStream out = new FileOutputStream("filename");
                  photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>And the exceptions in logcat:</p>
  
  <pre><code>04-02 14:46:51.975: W/IInputConnectionWrapper(2225): showStatusIcon on inactive InputConnection
  04-02 14:46:56.135: W/System.err(2225): java.io.FileNotFoundException: /filename (Read-only file system)
  04-02 14:46:56.135: W/System.err(2225):     at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
  04-02 14:46:56.145: W/System.err(2225):     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
  04-02 14:46:56.145: W/System.err(2225):     at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:94)
  04-02 14:46:56.145: W/System.err(2225):     at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:165)
  04-02 14:46:56.145: W/System.err(2225):     at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:144)
  </code></pre>