// Save it to the SD card private static String sdState = Environment. getExternalStorageState (); private static String path = Environment. getExternalStorageDirectory (). toString (); public static void saveBitmap (Bitmap bitmap, String imageName) {File file; File PicName; if (sdState. equals (Environment. MEDIA_MOUNTED) {// get the SD card root directory file = new File (path + "/Huai/TicketsPic"); if (! File. exists () {file. mkdirs ();} PicName = new File (file, imageName); try {if (! PicName. exists () {PicName. createNewFile ();} FileOutputStream fos = new FileOutputStream (PicName); if (PicName. getName (). endsWith (". png ") {bitmap. compress (CompressFormat. PNG, 100, fos);} else if (PicName. getName (). endsWith (". jpg ") {bitmap. compress (CompressFormat. JPEG, 100, fos);} fos. flush (); fos. close ();} catch (FileNotFoundException e) {e. printStackTrace ();} catch (IOException e) {e. printStackTrace () ;}}// get public static Bitmap getBitmap (String imageName) {Bitmap bitmap = null; File imagePic; if (sdState. equals (Environment. MEDIA_MOUNTED) {imagePic = new File (path + "/Huai/TicketsPic", imageName); if (imagePic. exists () {try {bitmap = BitmapFactory. decodeStream (new FileInputStream (imagePic);} catch (FileNotFoundException e) {// e. printStackTrace () ;}}return bitmap;} // Delete the SD card File public static void deleteFile (file File) {if (sdState. equals (Environment. MEDIA_MOUNTED) {if (file. exists () {if (file. isFile () {file. delete ();} // if it is a directory else if (file. isDirectory () {// declare all files in the directory []; File files [] = file. listFiles (); for (int I = 0; I <files. length; I ++) {// traverse all files in the directory deleteFile (files [I]); // iterate each file using this method} file. delete ();}}}