FileNotFoundExcecption while inserting image into SDCard.

Posted by Are on Stack Overflow See other posts from Stack Overflow or by Are
Published on 2010-12-31T07:11:45Z Indexed on 2010/12/31 11:54 UTC
Read the original article Hit count: 199

Filed under:

Hi,

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(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

© Stack Overflow or respective owner

Related posts about android