getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用,getfilesdir

Android开发:获取内部/外部存储路径 在APP开发过程中,有时会涉及到读写本地文件的操作,则先需要获取到存储路径。本教程介绍了获取内部和外部存储路径的方法。 阅读详情
getCacheDir()方法用于获取/data/data/<application package>/cache目录


getFilesDir()方法用于获取/data/data/<application package>/files目录


---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


应用程序在运行的过程中如果需要向手机上保存数据,一般是把数据保存在SDcard中的。
大部分应用是直接在SDCard的根目录下创建一个文件夹,然后把数据保存在该文件夹中。
这样当该应用被卸载后,这些数据还保留在SDCard中,留下了垃圾数据。
如果你想让你的应用被卸载后,与该应用相关的数据也清除掉,该怎么办呢?


通过Context.getExternalFilesDir()方法可以获取到 SDCard/Android/data/你的应用的包名/files/ 目录,一般放一些长时间保存的数据
通过Context.getExternalCacheDir()方法可以获取到 SDCard/Android/data/你的应用包名/cache/目录,一般存放临时缓存数据


如果使用上面的方法,当你的应用在被用户卸载后,SDCard/Android/data/你的应用的包名/ 这个目录下的所有文件都会被删除,不会留下垃圾信息。
而且上面二个目录分别对应 设置->应用->应用详情里面的”清除数据“与”清除缓存“选项






如果要保存下载的内容,就不要放在以上目录下






-----------------------------------------------------------------------------------------------------------------------------------------------------


较优秀的程序都会专门写一个方法来获取缓存地址,如下所示:




[java] view plaincopy
public String getDiskCacheDir(Context context) {  
    String cachePath = null;  
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())  
            || !Environment.isExternalStorageRemovable()) {  
        cachePath = context.getExternalCacheDir().getPath();  
    } else {  
        cachePath = context.getCacheDir().getPath();  
    }  
    return cachePath;  
}  
可以看到,当SD卡存在或者SD卡不可被移除的时候,就调用getExternalCacheDir()方法来获取缓存路径,否则就调用getCacheDir()方法来获取缓存路径。前者获取到的就是 /sdcard/Android/data/<application package>/cache 这个路径,而后者获取到的是 /data/data/<application package>/cache 这个路径。








参考:http://blog.csdn.net/beihai1212/article/details/7055899


http://blog.csdn.net/zhiyi2010/article/details/13017171


http://blog.csdn.net/guolin_blog/article/details/28863651






android程序扫描储存时,如果使用API:EnvironmentgetExternalStorageDirectory()getPath()获得的是默
可以先判断下Environment.getExternalStorageDirectory().getParentFile(),如果返回null则没有父路径,取Environment.getExternalStorageDirectory().getPath()为当前父路径。
 
Android开发:filePath放在哪个文件夹
Environment.getDataDirectory() = /data
Environment.getDownloadCacheDirectory() = /cache
Environment.getExternalStorageDirectory() = /mnt/sdcard
Environment.getExternalStoragePublicDirectory(“test”) = /mnt/sdcard/test
Environment.getRootDirectory() = /system
getPackageCodePath() = /data/app/com.my.app-1.apk
getPackageResourcePath() = /data/app/com.my.app-1.apk
getCacheDir() = /data/data/com.my.app/cache
getDatabasePath(“test”) = /data/data/com.my.app/databases/test
getDir(“test”, Context.MODE_PRIVATE) = /data/data/com.my.app/app_test
getExternalCacheDir() = /mnt/sdcard/Android/data/com.my.app/cache
getExternalFilesDir(“test”) = /mnt/sdcard/Android/data/com.my.app/files/test
getExternalFilesDir(null) = /mnt/sdcard/Android/data/com.my.app/files
getFilesDir() = /data/data/com.my.app/files
Android 11 访问 Android/data/或者getExternalCacheDir() 非root方式 SAF 提供了一种标准化的方式来让应用程序请求访问其他应用的文件和目录。要使用 SAF 请求访问 Android/data 目录。如果手机安卓版本为Android10的时候,可以在AndroidManifest.xml中添加下列代码。需求要求安装三方应用ExternalCacheDir()下载下来的apk文件。使用 Storage Access Framework 请求访问权限。以此禁用分区存储,但这在Android11及以上版本不起作用。 阅读详情

相关推荐

Android获取手机所有文件存储路径

博客地址:http://blog.csdn.net/lowprofile_coding/article/details/48269011 1.获取扩展存储设备 2.获取sdcard2外部存储空间 3.获取可用的 EMMC 内部存储空间 4.获取其他外部存储可用空间 5.获取内部存储目录

getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir() 解析

getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir() 解析 getCacheDir()  方法用于获取   /data/data//cache目录 getFilesDir()   方法用于获取   /data/data//files目录 Context.getExte

legend12300的专栏 2423

保姆级避坑指南:在Win10/Win11上搞定西门子博图V17完整安装(附注册表清理技巧)

本文提供了一份详细的西门子博图V17在Win10/Win11系统上的安装指南,涵盖从系统预检、注册表清理到分步安装的全过程。特别针对常见的安装失败问题,如PendingFileRenameOperations注册表残留和.NET Framework 3.5未启用等,提供了专业的解决方案和避坑技巧,帮助用户高效完成安装并优化性能。

weixin_29240711的博客 977

Android getFilesDir()、getCacheDir()、getExternalFilesDir()、getExternalCacheDir()的作用

getFilesDir、getCacheDir getFilesDir()方法用于获取/data/data/应用包名/files目录 getCacheDir()方法用于获取/data/data/应用包名/cache目录 getExternalFilesDir、getExternalCacheDir 应用程序在运行的过程中如果需要向手机上保存数据,一般是把数据保存在SDcard中的。大部分应...

GracefulGuigui的博客 3173

关于esp32蓝牙模块的使用——esp32学习笔记

关于esp32蓝牙模块的使用——esp32学习笔记 零、前言 esp32自带蓝牙模块可以让我们进行蓝牙连接并进行数据交换 一、经典蓝牙BT 首先来编写代码,经典蓝牙的使用非常简单,首先声明使用了BluetoothSerial这个库,然后使用SerialBT.begin函数设置蓝牙的名字,再然后就是设置配对码,由于这里没有用到配对码,所以我将注释掉。当配对成功我们就使用printf函数打印出蓝牙配对成功。 #include <Arduino.h> #include <BluetoothSer

qq_53965184的博客 5万+

(数字ic验证)从零开始的apb_watchdog验证模块搭建(一、功能介绍与环境搭建)

apb_watchdog验证模块搭建(一)文章目录 文章目录apb_watchdog验证模块搭建(一)文章目录前言一、apb_watchdog简单功能介绍二、测试平台环境搭建1.测试所用模板介绍2.tb与interface2.env与watchdog_pkg3.test与base_sequence4.Makefile总结——当前验证结构 前言 本文介绍了apb_watchdog验证模块的搭建过程与其具体代码,主要包括其中验证环境的构建,测试序列的发送与回归测试收集。主要运用systemvorilog与u

peop1e的博客 9758

【android】getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用

getCacheDir()方法用于获取/data/data//cache目录 getFilesDir()方法用于获取/data/data//files目录 --------------------------------------------------------------------------------------------------------------------

u011494050的专栏 5万+

自然语言处理:稀疏向量表示

稀疏向量表示是指运用特定的方法和技术,将数据(如文本、图像、信号等)转化为向量形式,且该向量具有大部分元素值为零,仅少数元素值非零的特征,以此来实现对数据的高效存储、处理和分析。

老赵爱学习的博客 1450

getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用

一.getCacheDir、getCacheDir getCacheDir()方法用于获取/data/data//cache目录 getFilesDir()方法用于获取/data/data//files目录 二.getExternalFilesDir、getExternalCacheDir   应用程序在运行的过程中如果需要向手机上保存数据,一般是把数据保存在SDcard中的。大部分应...

wqbs369的专栏 2064

java modbus通讯协议_Modbus通 讯 协 议

电磁流量计Modbus通 讯 协 议(版本号:9000-K V9.1.1)2020年01月01日通讯协议针对KFD电磁流量计工业应用设计,版本:9000-K V9.1.1,该版本主要用于实时数据采集、流量测量、流量累计控制及部分参数的修改。一、主机系统通讯部件要求1.国际标准RS-485通讯接口部件,不小于11Bytes 的通信缓冲区(FIFO),支持1200、2400、4800、96...

weixin_39956612的博客 1023

时间序列预测 | 决策树时间序列预测建模,单步、多步(Python)

时间序列预测 | 决策树时间序列预测建模,单步、多步(Python)

天天酷科研的博客 750

Android getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用

内部存储(Internal Storage) //路径:(data/data/packageName/cache) getCacheDir() //路径:(data/data/packageName/files) getFilesDir() 外部存储(External Storage) (1)公共文件(目录) //路径:/storage/emulated/0(SD卡的根目录) Envir...

Hly的博客 1802

教师模型与学生模型:知识蒸馏的核心概念

知识蒸馏,教师模型,学生模型,模型压缩,迁移学习,深度学习 1. 背景介绍 深度学习模型在图像识别、自然语言处理等领域取得了显著的成就,但其巨大的模型规模和高昂的计算成本限制了其在资源有限的设备上的部署。知识蒸馏(Knowledge Distillation)作为一种模型压缩技术,旨

AI架构师小马 2792

Context的getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用

【android】getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用 2014-09-29 21:14:18http://blog.csdn.net/u011494050/article/details/39671159--点击数:3435 ge

lzf的博客 1万+

YOLO26改进策略【注意力机制篇】| CVPR2025 MaIR SSA 序列洗牌注意力 多向序列通道加权 + 线性低开销聚合,强化纹理细节复原

四组不同扫描方向生成的序列携带上下文信息差异巨大,直接相加会混淆互补特征,丢失条带边界、纹理连续性信息;缺乏跨序列、对应通道的自适应权重分配能力,有效纹理、边缘特征与退化噪声无区分叠加,图像超分、去噪、去雾等任务细节恢复效果差;传统全局自注意力复杂度为ON2O(N^2)ON2,部署开销巨大,而普通通道注意力无法处理多向异构序列之间的依赖关系。因此设计SSA序列洗牌注意力,实现多扫描序列通道级自适应加权聚合,轻量建模跨序列全局依赖,保留图像局部性与连续性。

Limiiiing的博客 93

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

安卓目录地址getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用

转载:http://blog.csdn.net/a910626/article/details/51470866 一.getCacheDir、getCacheDir getCacheDir()方法用于获取/data/data//cache目录  getFilesDir()方法用于获取/data/data//files目录 二.getExternalFilesDir、ge

7108

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

[android]中getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用,getfilesdir

getCacheDir()方法用于获取/data/data//cache目录 getFilesDir()方法用于获取/data/data//files目录 应用程序在运行的过程中如果需要向手机上保存数据,一般是把数据保存在SDcard中的。 大部分应用是直接在SDCard的根目录下创建一个文件夹,然后把数据保存在该文件夹中。 这样当该应用被卸载后,这些数据还保留在SDC

Jason_996的博客 2358

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Android getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir() 的作用与区别

Android getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用与区别

桉树先生 1507

【android】getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用,getfilesdir

【android】getCacheDir()、getFilesDir()、getExternalFilesDir()、getExternalCacheDir()的作用,getfilesdir

qq_29586601的博客 471
上一篇: Android应用内语言切换实现
下一篇: svn中的revert和update
scyatcs
博客等级 码龄14年 237粉丝 75原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值