1 Add permission below <uses-sdk.../>
<uses-SDK android:minsdkversion= " android:targetsdkversion" = "/>" < Uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name= " Android.permission.MOUNT_UNMOUNT_FILESYSTEMS "/>
2 Add the following code below the OnCreate function:
1 //write files in SD2 Public voidWritefilesdcardfile (String FileName,byte[] bytes)throwsIOException3 { 4 Try5 { 6FileOutputStream Fout =NewFileOutputStream (fileName); 7 fout.write (bytes); 8 Fout.close (); 9 } Ten Catch(Exception e) One { A E.printstacktrace (); - } - } the - //read the files in SD - Public voidReadfilesdcardfile (String FileName,byte[] bytes)throwsIOException - { + Try - { +FileInputStream fin =NewFileInputStream (fileName); A fin.read (bytes); at Fin.close (); - } - Catch(Exception e) - { - E.printstacktrace (); - } in}
3 Call Place:
1 byte[] buffer =New byte[width*height]; 2 3 Try //Read the file4 {5Readfilesdcardfile ("/mnt/sdcard/2.raw", buffer);6 } 7 Catch(IOException e)8 {9 //TODO auto-generated Catch blockTen e.printstacktrace (); One } A - //Your program ... - the byte[] Arraydst2 =New byte[width*height]; - Try //Write a file - { -Writefilesdcardfile ("/mnt/sdcard/2out.raw", arraydst2); + } - Catch(IOException e) + { A //TODO auto-generated Catch block at e.printstacktrace (); -}
4 Main references:
http://blog.csdn.net/ztp800201/article/details/7322110
(original) file read and write in Java of Eclipse