内部存储(data/data/package/cache/):
*File file = new File(context.getFilesDir(), filename);
(不能直接文件夹+文件名,如果有文件夹需folder.mkdirs())
*openFileOutput(filename, Context.MODE_PRIVATE);
*File.createTempFile(fileName, null, context.getCacheDir());
(创建临时缓存文件,会自动在fileName后面加上**.temp)
*new File("/data/***", fileName);
(这也是存储到internal的,但最好别这么写,这样需要root,需要相应的权限,重新挂载rw模式。new File("/data/data/package/", fileName)可能可以读写)
外部存储(storage/):
*File file = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), fileName);(storage/Pictures/)
*File file = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES),fileName);
(storage/Android/data/package/file/Pictures/)
*new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + PATH + File.separator + fileName);(storage/path/)
最后:存储的文件要到别的应用打开的就别存到internal中(如下载了一份PDF文件存到internal中,然后让第三方应用打开就会有问题)
921

被折叠的 条评论
为什么被折叠?



