tags:

views:

13

answers:

1

I'm opening an image from the gallery, resizing it, and attempting to save the resized version to the apps data file so I can grab it in future. My problem is I keep getting a FileNotFoundException when I try to write it with an input stream.

This is the file it's trying to write too. "/mnt/sdcard/Android/data/foundcake.myslide/files/IMG_20100918_133128.png"

Am I missing any important steps here?

    File storagePath = new File(Environment.getExternalStorageDirectory() + "/Android/data/foundcake.myslide/files/");
    storagePath.mkdirs();

    Debug.print("STORAGE PATH " + storagePath);

    Pattern pattern = Pattern.compile("/([^/]+)\\.[^/]+$");
    Matcher matcher = pattern.matcher(filePath);
    String fileName = "";
    while (matcher.find()) {
        fileName = matcher.group(1);
    }

    Debug.print("FILE NAME " + fileName);

    File cached = new File(storagePath, fileName + ".png");

    Debug.print("NEW FILE " + cached.toString());

    try {
        FileOutputStream out = new FileOutputStream(cached);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
    } catch (Exception e) {
        e.printStackTrace();
    }
A: 

Needed

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Whoops.

Joren