开发者

FileNotFoundExcecption while inserting image into SDCard

I want to insert images into my SDCard.So I used below code

m_cImagePath = "/sdcard/"+ String.format("%d.jpg", System.currentTimeMillis());

        FileOutputStream lObjOutStream = null;
        try {
            lObjOutStream = new FileOutputStream(开发者_Go百科m_cImagePath);
            if (null != lObjOutStream && null != finalBitmap) {
                finalBitmap.compress(Bitmap.CompressFormat.JPEG, 85, lObjOutStream);
                lObjOutStream.close();
            }catch(FileNotFoundException fe){
fe.printStackTrace();
}

Sometimes it is giving FileNotFoundException even my SDCard had memory.When I remove some images from sdcard again it is working smoothly.Why this Happend?How can i know that file is inserted successfully in SDCard and Is there any functionality in Java1.5 to know available space of the SDCard like java 1.6?How can i know file length which is not before inserting into the SDCard(I searched in google and found that

"when the file is not physically there then file.length() always gives 0"

).But before inserting i want to know the length of the file.Then Comparing this space to available SDCard space is simple.

Note :I had an idea to use Unix command

df sdcard

using in

Runtime class

to found SDCard space.

Please give me an idea in this problem.

Regards, Android Developer


Never never never never never hardcode /sdcard in an Android application. First, it's wrong on Android 2.2+. Second, it's wrong on other devices as well. Always use Environment.getExternalStorageDirectory() for the root of external storage.

Is there any functionality in Java1.5 to know available space of the SDCard like java 1.6?

android.os.StatFs has what you need.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜