0

Can some one please let me know how to create a file of specific size on sd card programatically. I did tried shell command like this which is of no use,

try {
   Process p = Runtime.getRuntime().exec("dd of=/mnt/extSdCard/output.dat bs=1 seek=1M count=0");
} catch (IOException e1) {

}

I did even try the same command in shell script and was not able to create the file. I guess since my device is not rooted, this command did not work.

Any help regarding this highly appreciated.

-regards, Manju

Manju
  • 677
  • 5
  • 13
  • 27

2 Answers2

1

you can use RandomAccessFile as shown here.

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
0

First you obtain prermission for External storage. Edit the AndroidManifest.xml with the following line of code.

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

After that in java file write the following code. File fileName = new File(Environment.getExternalStorageDirectory(), "output.dat"); FileOutputStream fos = new FileOutputStream(fileName ) fos.write(bytes);