Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 各個存儲路徑的解釋

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.2cto.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

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved