Get the body storage path (can be operated via Openfileinput,openfileoutput)
String path=environment.getdatadirectory (). GetAbsolutePath (); return/data
Get the built-in SD card path:
Public String Getstoragedir () { if (! ( Environment.getexternalstoragestate (). Equals (environment.media_mounted)) { return ""; } File dirfile=environment.getexternalstoragedirectory (); LOG.D (TAG, Dirfile.getabsolutepath ()); return Dirfile.getabsolutepath (); }
Back to/storage/emulated/o
To obtain an external TF card path:
Idea: Through the Mount command in Linux.
Public String Gettfdir () {string path= ""; try {InputStream ins=runtime.getruntime (). EXEC ("mount"). getInputStream (); BufferedReader reader=new BufferedReader (New InputStreamReader (INS)); String line= "", while ((Line=reader.readline ())!=null) {if (Line.contains ("SDcard")) {if (Line.contains ("Vfat") | | Line.contains ("fuse")) {String split[]=line.split ("");p ath=split[1]; LOG.D (Tag,path);}}} Reader.close (); Ins.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Finally{}return path;}
Return/storage/sdcard1 This is the path we want.
Get free space
public static long Getavailablesize (String path) { try{ file base = new file (path); StatFs stat = new StatFs (Base.getpath ()); Long Navailablecount = Stat.getblocksize () * ((Long) stat.getavailableblocks ()); return navailablecount; } catch (Exception e) { e.printstacktrace (); } return 0; }
Returns the size of the bytes unit.
Android acquires body storage, built-in SD card and external TF card path