zoukankan      html  css  js  c++  java
  • Android-彻底理解文件存储

     
    All Android devices have two file storage areas: "internal" and "external" storage. These names come from the early days of Android, when most devices offered built-in non-volatile memory (internal storage), plus a removable storage medium such as a micro SD card (external storage). Some devices divide the permanent storage space into "internal" and "external" partitions, so even without a removable storage medium, there are always two storage spaces and the API behavior is the same whether the external storage is removable or not. The following lists summarize the facts about each storage space.
     
    总结:
      1. Internal storage:
        1. 只有当前app可以访问;
        2. 卸载时删除;
        3. getFileDir(),返回/data/data/com.dhn.test/files
        4. getCacheDir(),返回 /data/data/com.dhn.test/cache
      2. External storage:
        1. public:
          1. 所有app都可以访问
          2. 卸载时保留
          3. Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC):返回/storage/emulated/0/Music
        2. private:
          1. 所有app都可以访问
          2. 卸载时会删除
          3. getExternalFilesDir(Environment.DIRECTORY_MUSIC):返回/storage/emulated/0/Android/data/com.dhn.test/files/Music
      3. 注意点:无论使用public还是private的External storage时,使用api提供的常量作为目录名(DIRECTORY_RINGTONES),这样会被系统识别为铃声,而不是音乐。
      4. 实验:
         1 // /storage/emulated/0
         2 // sc卡根路径,卸载时会保留
         3 File f1 = Environment.getExternalStorageDirectory();
         4 Log.e("Main", f1.getAbsolutePath());
         5 
         6 // /storage/emulated/0/Music
         7 File f2 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
         8 Log.e("Main", f2.getAbsolutePath());
         9 
        10 // /data/data/com.dhn.test/files
        11 File f3 = getFilesDir();
        12 Log.e("Main", f3.getAbsolutePath());
        13 
        14 File f4 = getCacheDir();
        15 Log.e("Main", f4.getAbsolutePath());
        16 
        17 // /storage/emulated/0/Android/data/com.dhn.test/files/Music
        18 // 在SD卡中,卸载时会被删除
        19 File f5 = getExternalFilesDir(Environment.DIRECTORY_MUSIC);
        20 Log.e("Main", f5.getAbsolutePath());
         
  • 相关阅读:
    读书笔记之:数据结构,算法与应用(3)
    C++中的虚函数继承与虚继承
    读书笔记之:Effective STL
    C++虚函数及虚函数表解析
    类中的常量, const对象和成员函数
    读书笔记之:Boost程序库完全开发指南(Ch14)
    读书笔记之:C++探秘——68讲贯通C++
    读书笔记之:Boost程序库完全开发指南(ch516)
    配置java的环境变量
    查询并杀死死锁
  • 原文地址:https://www.cnblogs.com/gatsbydhn/p/5175298.html
Copyright © 2011-2022 走看看