(original) file read and write in Java of Eclipse

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.