Skip to content Skip to sidebar Skip to footer

Store Data Text To Sd Card In Android?

I have to store data text to SD Card. This is my code : try { File myFile = new File(Environment.getExternalStorageDirectory()+'/mnt/sdcard/mysdfile.txt');

Solution 1:

You can also try this https://github.com/uberspot/AndroidStorageUtils it's a wrapper class/package that makes storage usage in android a bit easier. :) It has a "saveStringOnExternalStorage" method as well.

Solution 2:

Try this code must solve issues...

try{
    Stringfilename="filename.txt";
    FilemyFile=newFile(Environment.getExternalStorageDirectory(), filename);

    if(!myFile.exists()) 
        myFile.createNewFile();
    FileOutputStream fos;
    byte[] data = txtData.getBytes();
    try {
        fos = newFileOutputStream(myFile);
        fos.write(data);
        fos.flush();
        fos.close();
    } 
    catch (FileNotFoundException e) {
    // handle exception
  } catch (IOException e) {
    // handle exception
  }

Post a Comment for "Store Data Text To Sd Card In Android?"