Android deletes SD card files and creates folders and files
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 the folder // Save the image public static void saveBitmap (Bitmap B M, String picName) {Log. e ("", "Save image"); 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, 90, out); out. flush (); out. 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. getExternalStorageState (). 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. exists ();} // delete an object Public static void delFile (String fileName) {File file = new File (SDPATH + fileName); if (file. isFile () {file. delete ();} file. exists () ;}// Delete the public static void deleteDir () {File dir = new File (SDPATH); if (dir = null |! Dir. exists () |! Dir. isDirectory () return; for (File file: dir. listFiles () {if (file. isFile () file. delete (); // delete all files else if (file. isDirectory () deleteDir (); // delete a folder} dir. delete (); // delete directory itself} public static boolean fileIsExists (String path) {try {File f = new File (path); if (! F. exists () {return false ;}} catch (Exception e) {return false ;}return true ;}}