Android Development SDcard response file related processing (i)

Source: Internet
Author: User

The processing tool class for Android development related file classes:

1  Packagecom.gzcivil.utils;2 3 ImportJava.io.File;4 Importjava.util.ArrayList;5 Importjava.util.List;6 7 Importandroid.os.Environment;8 ImportAndroid.os.StatFs;9 Ten Importcom.gzcivil.entity.FileEntity; One  A /** - * SDcard Related processing -  *  the  * @authorLijinlun -  *  -  */ -  Public classFileUtils { +  -     /** + * Get all files in the specified folder A      * @paramPath at      * @paramExtension -      * @paramisiterative -      * @return -      */ -      Public StaticList<fileentity> GetFiles (String Path, String Extension,Booleanisiterative)//Search directory, extension (to determine the name of the file type suffix), whether to enter subfolders -     { inList<fileentity> mlist =NewArraylist<fileentity>(); -         if(Mlist! =NULL&& mlist.size () > 0) to mlist.clear (); +file[] Files =NewFile (Path). Listfiles (); -         if(Files! =NULL) { the              for(inti = 0; i < files.length; i++) { *File f =Files[i]; $                 if(F.isfile ()) {Panax Notoginseng                     if(F.getpath (). substring (F.getpath (). Length ()-extension.length ()). Equals (Extension))//To determine the extension name -                     { theFileentity fileent =Newfileentity (); + Fileent.setnewname (F.getname ()); A fileent.setfilesize (Commonutil.formetfilesize (F.length ())); the Fileent.setfilepath (F.getpath ()); +  - Mlist.add (fileent); $                     } $                     if(!isiterative) -                          Break;//If you do not enter the subset directory, jump -}Else if(F.isdirectory () && F.getpath (). IndexOf ("/.") = = =-1)//Ignore point files (hidden files/folders) theGetFiles (F.getpath (), Extension, isiterative);//We're going to start recursion here. -             }Wuyi  the         } -         returnmlist; Wu     } -  About     /** $ * SDcard is present -      *  -      * @return -      */ A      Public Static BooleanExistsdcard () { +         if(Android.os.Environment.getExternalStorageState (). Equals (Android.os.Environment.MEDIA_MOUNTED)) { the             return true; -}Else $             return false; the     } the  the     /** the * SDcard remaining space -      *  in      * @return the      */ the      Public Static Longgetsdfreesize () { About         //get SD card file path theFile Path =environment.getexternalstoragedirectory (); theStatFs SF =NewStatFs (Path.getpath ()); the         //gets the size of a single data block (Byte) +@SuppressWarnings ("Deprecation") -         LongBlockSize =sf.getblocksize (); the         //the number of free data blocksBayi@SuppressWarnings ("Deprecation") the         LongFreeblocks =sf.getavailableblocks (); the         //return SD card idle size -         //return freeblocks * blockSize;//Unit byte -         //return (freeblocks * blockSize)/1024;//Unit KB the         return(Freeblocks * blockSize)/1024/1024;//units MB the     } the  the     /** - * SDcard Total capacity the      *  the      * @return the      */94      Public Static Longgetsdallsize () { the         //get SD card file path theFile Path =environment.getexternalstoragedirectory (); theStatFs SF =NewStatFs (Path.getpath ());98         //gets the size of a single data block (Byte) About@SuppressWarnings ("Deprecation") -         LongBlockSize =sf.getblocksize ();101         //get the number of all data blocks102@SuppressWarnings ("Deprecation")103         LongAllblocks =Sf.getblockcount ();104         //return SD card size the         //return allblocks * blockSize;//Unit byte106         //return (allblocks * blockSize)/1024;//Unit KB107         return(Allblocks * blockSize)/1024/1024;//units MB108     }109  the     //Delete the files in the SD card folder111      Public Static voiddeletefile (file file) { the         if(File.exists ()) {113             if(File.isfile ()) { the                 return; the}Else if(File.isdirectory ()) { the                 //if it's a directory117                 //all files under the Declaration directory files[];118File files[] =file.listfiles ();119                  for(inti = 0; i < files.length; i++) {//traverse all the files in the directory -DeleteFile (Files[i]);//iterate through each file in this way121                 }122             }123 File.delete ();124         } the     }126 127     /** - * Delete individual files129      *  the      * @paramfile131      */ the      Public Static voiddeletesinglefile (file file) {133         if(File.exists ()) {134             if(File.isfile ()) {135 File.delete ();136             }137         }138     }139}

Android Development SDcard response file related processing (i)

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.