当前位置:操作系统 > 安卓/Android >>

android 各个存储路径的解释

在android手机上存储文件是我们每个手机用户必不可少的功能,而对于开发者而言,熟练的操作各个文件,这样对于我们开发有很大帮助,下面androidkaifa.com就介绍一个android API文件为我们提供的那些获取文件路径的方法,它们所对应的实际文件路径是哪个文件,好了废话不多说,直接上代码!

package com.herongyang;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.ScrollView;
import android.os.Environment;
public class AboutAndroid extends Activity {
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      String msg = "";
     
      msg += "System properties\n";
      msg += "-------------\n";
      java.util.Properties props = System.getProperties();
      java.util.Enumeration e = props.propertyNames();
      while (e.hasMoreElements()) {
         String k = (String) e.nextElement();
         String v = props.getProperty(k);
         msg += k+": "+v+"\n";
      }

      msg += "\n";
      msg += "Envirionment variables\n";
      msg += "-------------\n";
      java.util.Map envs = System.getenv();
      java.util.Set keys = envs.keySet();
      java.util.Iterator i = keys.iterator();
      while (i.hasNext()) {
         String k = (String) i.next();
         String v = (String) envs.get(k);
         msg += k+": "+v+"\n";
      }

      msg += "\n";
      msg += "Environment folders\n";
      msg += "-------------\n";
      msg += "Data folder: "+Environment.getDataDirectory().getPath()+"\n";
      msg += "Download cache folder: "  +Environment.getDownloadCacheDirectory().getPath()+"\n";
      msg += "External Storage folder: " +Environment.getExternalStorageDirectory().getPath()+"\n";
      msg += "Root folder: "  +Environment.getRootDirectory().getPath()+"\n";

      msg += "\n";
      msg += "Application context info\n";
      msg += "-------------\n";
      msg += "Cache folder: "+getCacheDir().getPath()+"\n";
      msg += "External cache folder: "+getExternalCacheDir().getPath()+"\n";
      msg += "File folder: " +getFilesDir().getPath()+"\n";
      msg += "OBB folder: "+getObbDir().getPath()+"\n";
      msg += "Package name: " +getPackageName()+"\n";
      msg += "Package code path: "  +getPackageCodePath()+"\n";
      msg += "Package resource path: "+getPackageResourcePath()+"\n";

      TextView tv = new TextView(this);
      tv.setText(msg);
      ScrollView sv = new ScrollView(this);
      sv.addView(tv);
      setContentView(sv);
   }
}
运行应用程序我们可以得到如下信息::

Data folder: /data
Download cache folder: /cache
External storage folder: /mnt/sdcard
Root folder: /system  www.zzzyk.com

 

Cache folder: /data/data/com.herongyang/cache
External cache folder: /mnt/sdcard/Android/data/com.herongyang/cache
File folder: /data/data/com.herongyang/files
OBB folder: /mnt/sdcard/Android/obb/com.herongyang
Package name: com.herongyang
Package code path: /data/app/com.herongyang-1.apk
Package resource path: /data/app/com.herongyang-1.apk

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,