Android 文件基础认识

内部存储(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中,然后让第三方应用打开就会有问题)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值