Questions about Android SDCard Storage

Source: Internet
Author: User

Use Activit's openFileOutput () method to save the file, which is placed inside the mobile phone;
Note: create an image file for the SDCard in the simulator. You can create an image file in the simulator or install the tools directory in the android SDK installation path in the Dos window. Run the following command: mksdcard 2048 m d: \ AndroidTool \ sdcard. img
To access SDCard in a program, you must:Permission:
Permission to create and delete files in SDCard
<Uses-permission android: name = "android. permission. MOUNT_UNMOUNT_FILESYSTEMS"/>
Write Data permission in SDCard
<Uses-permission android: name = "android. permission. WRITE_EXTERNAL_STORAGE"/>

Public void saveToSDCard (String filename, String filecontent) throws IOException {
File file = new File (Environment. getExternalStorageDirectory (), filename); // get the path of the SDCard
FileOutputStream outStream = new FileOutputStream (file );
OutStream. write (filecontent. getBytes ());
OutStream. close ();
}

//Determine whether the SD card exists and can be read and written
// If (Environment. getExternalStorageState (). equals (Environment. MEDIA_MOUNTED )){
// Fs. saveToSDCard (filenamestr, filecontentstr );
// Toast. makeText (getApplicationContext (), R. string. success, 1). show ();
//} Else {
// Toast. makeText (getApplicationContext (), R. string. sdcarderror, 1). show ();
//}

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.