Android: writing a file to sdcard

Posted by Sumit M Asok on Stack Overflow See other posts from Stack Overflow or by Sumit M Asok
Published on 2010-03-16T14:25:56Z Indexed on 2010/03/17 4:11 UTC
Read the original article Hit count: 523

Filed under:
|
|

I'm trying to write a file from an Http post reply to a file on the sdcard. Everything works fine until the byte array of data is retrieved.

I've tried setting WRITE_EXTERNAL_STORAGE permission in the manifest and tried many different combinations of tutorials I found on the net.

All I could find was using the openFileOutput("",MODE_WORLD_READABLE) method, of the activity but how my app writes file is by using a thread. Specifically, a thread is invoked from another thread when a file has to be written, so giving an activity object didn't work even though I tried it.

The app has come a long way and I cannot change how the app is currently written. Please, someone help me?

CODE:

    File file = new File(bgdmanip.savLocation);
    FileOutputStream filecon = null;
            filecon = new FileOutputStream(file);

// bgdmanip.savLocation holds the whole files path

        byte[] myByte;
        myByte = Base64Coder.decode(seReply);
        Log.d("myBytes", String.valueOf(myByte));
        bos.write(myByte);
        filecon.write(myByte);
        myvals = x * 11024;

seReply is a string reply from HttpPost response. the second set of code is looped with reference to x. the file is created but remains 0 bytes

© Stack Overflow or respective owner

Related posts about android

Related posts about file-io