Record a often need to apply to the file related content, saying good memory than bad writing!
1)
<strong>/** * Based on the path, the total size of memory space of the memory in which a file or folder resides * * @return */public static long gettotalmemorysize (String path) { StatFs stat = new StatFs (path); Long blockSize = Stat.getblocksize (); Each block occupies a number of bytes long totalblocks = Stat.getblockcount (); Block Total Return totalblocks * blockSize;} </strong>
2)
/** * Based on path, how much memory space for a file or folder is available * * @return */public static long getavailablememorysize (String path) {StatFs s tat = new StatFs (path); Long blockSize = Stat.getblocksize (); Long availableblocks = Stat.getavailableblocks (); return Availableblocks * BLOCKSIZE;}
3)
/** * Gets the size of the specified file * * @param f * @return * @throws Exception */private static long getfilesize (file file) {Long size = 0 if (file.exists ()) {FileInputStream FIS = null;try {fis = new FileInputStream (file);//Use FileInputStream to read the data stream in file size = Fis.available ();//size of File} catch (IOException e) {e.printstacktrace ();} finally{try {Fis.close ();} catch (IOException e) { E.printstacktrace ();}}} else {LOG.E (TAG, "File not exists!");} return size;}
4)
/** * Gets the size of the specified folder * * @param f * @return * @throws Exception */private static long getfilesizes (File f) {long size = 0; File flist[] = F.listfiles ()///folder directory for all files for (int i = 0; i < flist.length; i++) {if (Flist[i].isdirectory ()) {//= parent) There's a subdirectory. Size = size + getfilesizes (Flist[i]);} else {size = size + getfilesize (Flist[i]);}} return size;}
5)Use this method to prevent multiple pop-up reminders when a toast is triggered multiple times
Private Toast mtoast = null;private void Showtoast (context context, String str) {if (mtoast = = null) {Mtoast = Toast.maket EXT (context, str, toast.length_short);} else {mtoast.settext (str);} Mtoast.show ();}
File related actions:
1) String name = File.getname ();// get the file or folder names:
2) File.mkdir (); Create a folder
3) File.createnewfile ();//Build file
4) file.isdirectory ();// judgment is a file or folder
5) File.isdirectory ()
6) file[] files = file.listfiles ();// list all file and folder names under Folders
7) File.renameto (dest);// Modify folder and file name
8) File.delete ();// Delete a folder or file
9) Childfiles[i].getname (). Contains ("TestFolder");// determine if a file name contains "TestFolder"
Android Development accumulate _1) get the user-friendly use of files, folder storage, and toasts