Android开发中各种目录

发布时间:2024年01月11日
java.io.File cacheDir = getCacheDir();
android.util.Log.d("debug", "cacheDir->" + cacheDir.getPath());
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.N) {
    java.io.File dataDir = getDataDir();
    android.util.Log.d("debug", "dataDir->" + dataDir.getPath());
}
java.io.File filesDir = getFilesDir();
android.util.Log.d("debug", "filesDir->" + filesDir.getPath());
java.io.File xmlDir = getDir("xml", MODE_PRIVATE);
android.util.Log.d("debug", "xmlDir->" + xmlDir.getPath());
java.io.File dataDirectory = android.os.Environment.getDataDirectory();
android.util.Log.d("debug", "dataDirectory->" + dataDirectory.getPath());
java.io.File downloadCacheDirectory = android.os.Environment.getDownloadCacheDirectory();
android.util.Log.d("debug", "downloadCacheDirectory->" + downloadCacheDirectory.getPath());
java.io.File rootDirectory = android.os.Environment.getRootDirectory();
android.util.Log.d("debug", "rootDirectory->" + rootDirectory.getPath());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.R) {
    java.io.File storageDirectory = android.os.Environment.getStorageDirectory();
    android.util.Log.d("debug", "storageDirectory->" + storageDirectory.getPath());
}
java.io.File externalCacheDir = getExternalCacheDir();
android.util.Log.d("debug", "externalCacheDir->" + externalCacheDir.getPath());
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
    java.io.File[] externalMediaDirs = getExternalMediaDirs();
    if (externalMediaDirs != null && externalMediaDirs.length > 0) {
        for (java.io.File file : externalMediaDirs) {
            android.util.Log.d("debug", "遍历外部媒介目录->" + file.getPath());
        }
    }
}
java.io.File[] externalCacheDirs = getExternalCacheDirs();
if (externalCacheDirs != null && externalCacheDirs.length > 0) {
    for (java.io.File file : externalCacheDirs) {
        android.util.Log.d("debug", "遍历外部缓存目录->" + file.getPath());
    }
}

debug: cacheDir->/data/user/0/com.example.test/cache
debug: dataDir->/data/user/0/com.example.test
debug: filesDir->/data/user/0/com.example.test/files
debug: xmlDir->/data/user/0/com.example.test/app_xml
debug: dataDirectory->/data
debug: downloadCacheDirectory->/data/cache
debug: rootDirectory->/system
debug: storageDirectory->/storage
debug: externalCacheDir->/storage/emulated/0/Android/data/com.example.test/cache
debug: 遍历外部媒介目录->/storage/emulated/0/Android/media/com.example.test
debug: 遍历外部缓存目录->/storage/emulated/0/Android/data/com.example.test/cache
debug: externalStorageDirectory->/storage/emulated/0

文章来源:https://blog.csdn.net/HardProgrammer/article/details/135530538
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。