English 中文(简体)
Android card片
原标题:Android writing bitmap to sdcard

I m trying to write a bitmap to an sdcard on android, and I get the error message of
/mnt/sdcard/PhysicsSketchpad/sketchpad145.png (No such file or directory).
I declared the android.permission.WRITE_EXTERNAL_STORAGE permission in the manifest, and this is my code:

String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + 
                        "/PhysicsSketchpad/";
File dir = new File(file_path);
dir.mkdirs();
File file = new File(dir, "sketchpad" + pad.t_id + ".png");
FileOutputStream fOut = new FileOutputStream(file);

bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();

What s going on?

<><>>>>><>>>>><>>>>>>

似乎在我试图写给现有名录时,我获得了否认错误的许可:

08-11 09:55:23.796: WARN/Physics Sketchpad(8881): Error when saving: IOException /mnt/sdcard/download/sketchpad54.png (Permission denied)

并且当我试图在新目录中节省费用时,我没有发现这种档案或目录错误,08-11 09:59:20.175:WARN/Physics Sketchpad(9040):Error在储蓄时:IOException /mnt/sdcard/PhysketicsSchpad/sketpad55.png (无此类档案或目录)

此外,<代码>File.mkdirs(>)如果成功或未成功,就返回了养蜂业,并退回了伪造。

最佳回答

尝试这项法典。

  String file_path = Environment.getExternalStorageDirectory().getAbsolutePath() + 
                            "/PhysicsSketchpad";
    File dir = new File(file_path);
if(!dir.exists)
    dir.mkdirs();
    File file = new File(dir, "sketchpad" + pad.t_id + ".png");
    FileOutputStream fOut = new FileOutputStream(file);

    bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
    fOut.flush();
    fOut.close();
问题回答

尝试这项法典。 这为我工作。

public void saveBitmap(Bitmap bm)
{
    try
    {
        String mBaseFolderPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/";
        String mFilePath = mBaseFolderPath + "abcd.jpg";

        FileOutputStream stream = new FileOutputStream(mFilePath);
        bm.compress(CompressFormat.JPEG, 100, stream);
        stream.flush();
        stream.close();
    }
    catch(Exception e)
    {
        Log.e("Could not save", e.toString());
    }
}

Shash

你们将绝对道路检查到你走过道路的错误

/mnt/sdcard/AppName/appname145.png

Environment.getExternalStorageDirectory().getAbsolutePath() + 
                        "/PhysicsSketchpad/";

哪里作为“物理学家”的跳板,就不走过这条路。

审判

Environment.getExternalStorageDirectory().toString()+ "/PhysicsSketchpad/";




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签