Android 文件目录测试结果
2018-06-18 01:56:55来源:未知 阅读 ()
测试代码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
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:RabbitMQ基础入门
- eclipse下创建Maven项目(包含webapp目录结构) 2020-06-09
- Spring Boot 实现配置文件加解密原理 2020-06-08
- Java跨平台原理(字节码文件、虚拟机) 以及Java安全性 2020-06-07
- 【Java-jxl插件】【Excel文件读写报错】jxl.read.biff.BiffE 2020-06-07
- IDEA下Maven的pom文件导入依赖出现Auto build completed wit 2020-06-07
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash