Android File system path

Source: Internet
Author: User

(i) Get total root file[] FileList=file.listroots (); //returns filelist.length to 1//Filelist.getabsolutepath () is "/"//This is the total root of the system.(ii) Open the total root directory file file=NewFile ("/"); File[] FileList=File.listfiles (); //Get the directory in addition to "/sdcard" and "/system" there are "/data", "/cache", "/dev" and so on//the root directory of Android is not divided into C-disk, D-disk, e-disk, etc. as Symbian System.//Android is Linux-based, only directories, no matter the drive letter(iii) Get the system storage root file file=environment.getrootdirectory ();//file File=new file ("/system"); File[] Filelist=File.listfiles (); //the system here refers only to "/system."//The range of phones that do not include external storage is much larger than the so-called system storage(d) Get the SD card storage root directory (and the system's Public Media folder set on SD card: Camera, movie, picture, music ...) ) file File=environment.getexternalstoragedirectory ();//file File=new file ("/sdcard"); File[] Filelist=File.listfiles (); //to obtain an SD card, first verify that the SD card is loaded    Booleanis=environment.getexternalstoragestate (). Equals (environment.media_mounted); //If True, it is loaded//If False, it is not loadedFile pictures = Environment.getexternalstoragestate (). Equals (Environment.directory_pictures);//file File=new file ("/pictures"); Environment:directory_music,//AudioDirectory_podcasts,//Podcast VideosDirectory_ringtones,//Ringtone AudioDirectory_alarms,//Alarm AudioDirectory_notifications,//Message AudioDirectory_pictures,//ImageDirectory_movies,//VideoDirectory_downloads,//DownloadDirectory_dcim//Camera/Camera*******Create your own cache directory, use the cache directory on SD If the SD card is present, use the system cache directory if it does not existFinalString CachePath = Environment.MEDIA_MOUNTED.equals (Environment.getexternalstoragestate ()) | | !isexternalstorageremovable ()?Getexternalcachedir (context). GetPath (): Context.getcachedir (). GetPath (); File Mycachefile=NewFile (CachePath + file.separator + "Mycachefile"); //determine if the SD is built-in or removable and requires API 9@TargetApi (9)     Public Static Booleanisexternalstorageremovable () {if(Build.VERSION.SDK_INT >=Build.version_codes. Gingerbread) {returnenvironment.isexternalstorageremovable (); }        return true; }            //get the SD card cache directory, API 8 and above can be directly obtained, the following need to build their own directory@TargetApi (8)     Public StaticFile Getexternalcachedir (context context) {if(Build.VERSION.SDK_INT >=Build.version_codes. FROYO) {returnContext.getexternalcachedir (); }        //before Froyo we need to construct the external cache dir ourselves        FinalString Cachedir = "/android/data/" + context.getpackagename () + "/cache/"; return NewFile (Environment.getexternalstoragedirectory (). GetPath () +Cachedir); } ********(v) Get the data root directory file file=environment.getdatadirectory ();//file File=new file ("/data"); File[] Filelist=File.listfiles (); //because the Data folder is a very important folder in Android, general permissions are not available to the file, that is, Filelist.length returns 0(vi) Get private file path context context= This;//first, get context in the activity.File file=Context.getfilesdir (); String Path=File.getabsolutepath (); //The path returned here is/data/data/packet/files, where the package is the package where we built the main activity//we can see that this path is also in the Data folder//The program itself can operate on its own private files//Many of the private data in the program is written to the private file path, which is one of the reasons why Android protects data(vii) Get file (clip) absolute path, relative path strength, file (folder) name, parent directory=... String RelativePath=file.getpath ();//relative PathString Absolutepath=file.getabsolutepath ();//Absolute PathString Filename=file.getname ();//file (clip) nameString parentpath=file.getparent ();//Parent Directory(eight) list all files and folders under folder file=... File[] FileList=File.listfiles (); (ix) Determine whether the file or folder=...BooleanIs=file.isdirectory ();//true-Yes, false-no(10) Determine if file (folder) exists=...BooleanIs=file.exists ();//true-Yes, false-no(11) New File (folder)=... Oolean is=file.isdirectory ();//determine if a folder    /*Method 1*/      if(IS) {String path=File.getabsolutepath (); String name= "ABC";//you want to create a new folder name or file nameString pathx=path+name; File Filex=NewFile (PATHX); BooleanIs=filex.exists ();//determine if a file (clip) exists        if(!is ) {Filex.mkdir ();//Create a folder//filex.createnewfile ();//Create a file        }      /*Method 2*/      if(IS) {String path=File.getabsolutepath (); String name= "Test.txt";//you want to create a new folder name or file nameFile filex=NewFile (Path,name);//the difference between Method 1 and Method 2 is that this        BooleanIs=filex.exists ();//determine if a file (clip) exists        if(!is ) {Filex.mkdir ();//Create a folder//filex.createnewfile ();//Create a file} (12) renaming files (clips) file=... String Parentpath=file.getparent (); String NewName= "Name";//renamed file or folder nameFile filex=NewFile (Parentpath,newname);//file Filex=new file (parentpaht+newname)File.renameto (Filex); (13) Delete files (folder) file file=... file.delete ();//Delete now//file.deleteonexit ();//deleted after the program exits, only normal exit will be deleted----------------------------------------------------------------------------------------------

Android File system path

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.