众所周知,当前Android分为内部存储和外部存储(手机自带),同时还可以插入sd卡来扩展内存。
现在我们来简单介绍一下getExternalFilesDir(String type)方法:
- 该方法用于获得外部存储,地址为/storage/emulated/0/Android/data/packageName/files
- 该方法可传一个String类型的参数,表述为该路径下的文件夹,没有该文件夹会自动创建
- 使用方法:
String path=context.getExternalFilesDir(null).getAbsolutePath();
File file=new File(path);
//输出:path:/storage/emulated/0/Android/data/backageName/files
String path2=context.getExternalFilesDir("UniApp").getAbsolutePath();
File file2=new File(path2);
//path:/storage/emulated/0/Android/data/packageName/files/UniApp
//如uniapp文件夹没有,则会自动创建
String path3=context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
File file3=new File(path3);
//path:/storage/emulated/0/Android/data/packageName/files/Download
String path4=context.getExternalFilesDir("").getAbsolutePath()+"/hhhhhh";
File file4=new File(path4);
//path:storage/emulated/0/Android/data/packageName/files/hhhhhh
//如果没有“hhhhhh”文件夹,则file4.exists()==false;
packageName: app的包名
如果有错误,请指出,感谢~