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