Android 文件目录测试结果

2018-06-18 01:56:55来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

测试代码1:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

android.util.Log.e("wenqiao", "Environment.getDataDirectory():" + android.os.Environment.getDataDirectory().getAbsolutePath() + "\n");
android.util.Log.e("wenqiao", "Environment.getExternalStorageDirectory():" + android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "\n");
android.util.Log.e("wenqiao", "Environment.getRootDirectory():" + android.os.Environment.getRootDirectory().getAbsolutePath() + "\n");
android.util.Log.e("wenqiao", "Environment.getDownloadCacheDirectory():" + android.os.Environment.getDownloadCacheDirectory().getAbsolutePath());
/**
* 这个方法接收一个参数,表明目录所放的文件的类型,传入的参数是Environment类中的DIRECTORY_XXX静态变量,比如DIRECTORY_DCIM等.
* 注意:传入的类型参数不能是null,返回的目录路径有可能不存在,所以必须在使用之前确认一下,比如使用File.mkdirs创建该路径。
*/
java.io.File path = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_ALARMS);
if( !path.exists() ){
path.mkdirs();
}
/* /storage/emulated/0/Alarms */
android.util.Log.e("wenqiao", "Environment.getExternalStoragePublicDirectory():" + android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_ALARMS));

/**
* contextWrapper
*/
android.util.Log.e("wenqiao", "getCacheDir():" + this.getCacheDir().getAbsolutePath());
android.util.Log.e("wenqiao", "getFilesDir():" + this.getFilesDir().getAbsolutePath());
android.util.Log.e("wenqiao", "getExternalCacheDir():" + this.getExternalCacheDir().getAbsolutePath());
android.util.Log.e("wenqiao", "getExternalFilesDir():" + this.getExternalFilesDir(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath());
android.util.Log.e("wenqiao", "getPackageResourcePath():" + this.getPackageResourcePath());
android.util.Log.e("wenqiao", "getDir():" + this.getDir("myfile", android.content.Context.MODE_PRIVATE));
}

输出结果(myapplication为包名):

Environment.getDataDirectory():/data
Environment.getExternalStorageDirectory():/storage/emulated/0
Environment.getRootDirectory():/system
Environment.getDownloadCacheDirectory():/data/cache
Environment.getExternalStoragePublicDirectory():/storage/emulated/0/Alarms
getCacheDir():/data/user/0/com.example.mushr.myapplication/cache
getFilesDir():/data/user/0/com.example.mushr.myapplication/files
getExternalCacheDir():/storage/emulated/0/Android/data/com.example.mushr.myapplication/cache
getExternalFilesDir():/storage/emulated/0/Android/data/com.example.mushr.myapplication/files/DCIM
getPackageResourcePath():/data/app/com.example.mushr.myapplication-1/base.apkgetDir():/data/user/0/com.example.mushr.myapplication/app_myfile

 

 

测试代码2:

 
public static void getEnvironmentDirectories() {
android.util.Log.e(LOG_TAG, "getRootDirectory(): "
+ android.os.Environment.getRootDirectory().toString());
android.util.Log.e(LOG_TAG, "getDataDirectory(): "
+ android.os.Environment.getDataDirectory().toString());
android.util.Log.e(LOG_TAG, "getDownloadCacheDirectory(): "
+ android.os.Environment.getDownloadCacheDirectory().toString());
android.util.Log.e(LOG_TAG, "getExternalStorageDirectory(): "
+ android.os.Environment.getExternalStorageDirectory().toString());

android.util.Log.e(
LOG_TAG,
"getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES): "
+ android.os.Environment.getExternalStoragePublicDirectory(
android.os.Environment.DIRECTORY_PICTURES).toString());

// Log.i(
// LOG_TAG,
// "isExternalStorageEmulated(): "
// + Environment.isExternalStorageEmulated());
//
// Log.i(
// LOG_TAG,
// "isExternalStorageRemovable(): "
// + Environment.isExternalStorageRemovable());

}

public static void getApplicationDirectories(android.content.Context context) {

android.util.Log.e(LOG_TAG, "context.getFilesDir(): "
+ context.getFilesDir().toString());
android.util.Log.e(LOG_TAG, "context.getCacheDir(): "
+ context.getCacheDir().toString());

// methods below will return null if the permissions denied
android.util.Log.e(
LOG_TAG,
"context.getExternalFilesDir(Environment.DIRECTORY_MOVIES): "
+ context
.getExternalFilesDir(android.os.Environment.DIRECTORY_MOVIES));

android.util.Log.e(
LOG_TAG,
"context.getExternalCacheDir(): "
+ context.getExternalCacheDir());
}

测试结果2:

getRootDirectory(): /system
getDataDirectory(): /data
getDownloadCacheDirectory(): /data/cache
getExternalStorageDirectory(): /storage/emulated/0
getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES): /storage/emulated/0/Pictures
context.getFilesDir(): /data/user/0/com.example.mushr.myapplication/files
context.getCacheDir(): /data/user/0/com.example.mushr.myapplication/cache
context.getExternalFilesDir(Environment.DIRECTORY_MOVIES): /storage/emulated/0/Android/data/com.example.mushr.myapplication/files/Movies
context.getExternalCacheDir(): /storage/emulated/0/Android/data/com.example.mushr.myapplication/cache

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Apache软件基金会项目百度百科链接

下一篇:RabbitMQ基础入门