Android deletes SD card files and creates folders and files

Source: Internet
Author: User

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 ;}}

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.