Android Delete SD card file

Source: Internet
Author: User

<!--Create and delete files in SDcard permissions --
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<!--write data to SDcard permissions --

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


Delete a file

FileName = "/sdcard/myimage/" + image;




Remove the SD card folder

<span style= "white-space:pre" ></span>//remove SD card file <span style= "White-space:pre" ></span> public static void DeleteFile (file file) {<span style= "White-space:pre" ></span>if ( Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {<span style= "White-space:pre" > </span>if (File.exists ()) {<span style= "White-space:pre" ></span>if (File.isfile ()) {<span style = "White-space:pre" ></span>file.delete (); <span style= "White-space:pre" ></span>}<span Style= "White-space:pre" ></span>//if it is a directory <span style= "White-space:pre" ></span>else if ( File.isdirectory ()) {<span style= "white-space:pre" ></span>//declaration directory for all Files Files[];<span style= " White-space:pre "></span>file files[] = File.listfiles (); <span style=" White-space:pre "></span> for (int i = 0; i < files.length; i++) {//Traverse directory All Files <span style= "White-space:pre" ></span>deletefile (Files [i]); //Use this method to iterate over each file <span style= "White-space:pre" ></span>}<span style= "White-space:pre" ></span >}<span style= "White-space:pre" ></span>file.delete (); <span style= "White-space:pre" ></ Span>}<span style= "White-space:pre" ></span>}<span style= "White-space:pre" &GT;&LT;/SPAN&GT;}



SD Card write: http://blog.csdn.net/zhaoyazhi2129/article/details/8994295

Android Delete SD card file

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.