Save apps to sd card android source code..

1. First add the following permission to manifest.xml


<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


2. Use the following code in your apps.


String filename = "filename.txt";
File file = new File(Environment.getExternalStorageDirectory(), filename);
FileOutputStream fos;
byte[] data = new String("data to write to file").getBytes();
try {
fos = new FileOutputStream(file);
fos.write(data);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
// handle exception
} catch (IOException e) {
// handle exception
}


Source

No comments:

Post a Comment