Android Delete SD card files and files and create folders and files

Source: Internet
Author: User

Package Com.jiub.client.mobile.addphoto;import Java.io.file;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import Java.io.ioexception;import Android.graphics.bitmap;import android.os.Environment; Import Android.util.log;public class FileUtils {public static String Sdpath = Environment.getexternalstoragedirectory () + "/formats/";//Get Folder//Save picture public static void Savebitmap (Bitmap BM, String picname) {log.e ("", "Save Picture"); LOG.D ("text", Sdpath), try {if (!isfileexist (")") {File Tempf = Createsddir ("");} File F = new file (Sdpath, Picname + ". JPEG "); if (f.exists ()) {F.delete ();} FileOutputStream out = new FileOutputStream (f); bm.compress (Bitmap.CompressFormat.JPEG, N, out); Out.flush (); O Ut.close (); LOG.E ("", "Saved");} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ()}} public static File Createsddir (String dirName) throws IOException {file Dir = new File (Sdpath + dirName); if (environment.g Etexternalstoragestate (). Equals (Environment.media_mounted)) {System.out.println ("Createsddir:" + Dir.getabsolutepath ()); System.out.println ("Createsddir:" + dir.mkdir ());} return dir;} public static Boolean isfileexist (String fileName) {File File = new file (Sdpath + fileName); File.isfile (); return File.exis TS ();} Delete file public static void Delfile (String fileName) {File File = new file (Sdpath + fileName), if (File.isfile ()) {File.delete (        ); }file.exists ();} Delete files inside folders and folders public static void Deletedir () {File dir = new file (Sdpath); if (dir = = null | |!dir.exists () | | |!dir.isdir Ectory ()) return;for (file File:dir.listFiles ()) {if (File.isfile ()) file.delete ();//delete all files else if (File.isdirectory () ) Deletedir (); A recursive way to delete a folder}dir.delete ();//delete the directory itself}public the static Boolean fileisexists (String path) {try {file F = new File (path), if (!f. Exists ()) {return false;}} catch (Exception e) {return false;} return true;}}

Android Delete SD card files and files and create folders and files

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.