Android中关于内部存储的一些重要函数
public abstract File getCacheDir ()
Returns the absolute path to the application specific cache directory on
the filesystem. These files will be ones that get deleted first when
the device runs low on storage. There is no guarantee when these files
will be deleted. Note: you should not rely on
the system deleting these files for you; you should always have a
reasonable maximum, such as 1 MB, for the amount of space you consume
with cache files, and prune those files when exceeding that space.
存储空间剩余多少的情况,没有严格的标准保障。
注意:你不应该依赖系统来清理这些缓存文件,你应该对这些缓存文件占用的最大存储空间设定个最大值,比如是1M,当实际占用空间超过这个值时,你应该对这些缓存文件做相应的清理工作(prune)。
Returns
- Returns the path of the directory holding application cache files.
See Also
openFileOutput(String,
int)getFileStreamPath(String)
getDir(String,
int)- import android.app.Activity;
- import android.content.Context;
- import android.os.Bundle;
- import android.util.Log;
- public class MainActivity extends Activity {
- final static String TAG="robin";
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Context context=this;
- String path=context.getCacheDir().getAbsolutePath();
- Log.i(TAG,"path:"+path);
- }
- }
- path:/data/data/com.lenovo/cache
public abstract File getDir (String name,
int mode)
Retrieve, creating if needed, a new directory in which the application
can place its own custom data files. You can use the returned File
object to create and access files in this directory. Note that files
created through a File object will only be accessible
by your own application; you can only set the mode of the entire
directory, not of individual files.
:参数是指文件夹的访问权限而并不包括其子文件夹和文件的访问权限
Parameters
name
Name of the directory to retrieve. This is a directory that is created as part of your application data. | |
mode |
Operating mode. Use 0 or MODE_PRIVATE forthe default operation, MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE tocontrol permissions. |
---|
Returns
- Returns a File object for the requested directory. The directory will have been created if it does not already exist.
See Also
openFileOutput(String,
int)- File file=context.getDir("download", Context.MODE_PRIVATE);
- String path=file.getAbsolutePath();
- Log.i(TAG,"path:"+path);
public abstract File getFileStreamPath (String name)
Since: API Level 1Returns the absolute path on the filesystem where a file created with
openFileOutput(String,
is stored.
int)Parameters
name
The name of the file for which you would like to get its path. Returns
- Returns an absolute path to the given file.
See Also
openFileOutput(String,
int)getFilesDir()
getDir(String,
int)- File file=context.getFileStreamPath("download");
- String path=file.getAbsolutePath();
- Log.i(TAG,"path:"+path);
public abstract File getFilesDir ()
Since: API Level 1Returns the absolute path to the directory on the filesystem where files created with
openFileOutput(String,
are stored.
int)Returns
- Returns the path of the directory holding application files.
示例4File file=context.getFilesDir();String path=file.getAbsolutePath();Log.i(TAG,"path:"+path);运行结果10-02 09:15:11.102: I/robin(12359): path:/data/data/com.lenovo/filespublic abstract FileInputStream openFileInput (String name)
Since: API Level 1Open a private file associated with this Context's application package for reading.
Parameters
name The name of the file to open; can not contain path separators. Returns
- FileInputStream Resulting input stream.
Throws
FileNotFoundException public abstract FileOutputStream openFileOutput (String name, int mode)
Since: API Level 1Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.
Parameters
name The name of the file to open; can not contain path separators. mode Operating mode. Use 0 or MODE_PRIVATE
for the default operation,MODE_APPEND
to append to an existing file,MODE_WORLD_READABLE
andMODE_WORLD_WRITEABLE
to control permissions.Returns
- FileOutputStream Resulting output stream.
Throws
FileNotFoundException See Also
示例5
public abstract boolean deleteFile (String name)
Delete the given private file associated with this Context's application package.
Parameters
name
The name of the file to delete; can not contain path separators. |
Returns
- True if the file was successfully deleted; else false.
public abstract String[] fileList ()
Returns an array of strings naming the private files associated with this Context's application package.
Returns
- Array of strings naming the private files.
Gets the Android data directory.
用File返回数据文件的根目录,返回的文件的路径为“/data”。该目录下的文件是只读。应用程序无法对该目录下的文件进行写操作。
Gets the android Download/Cache content directory.
用File返回缓存文件的根目录,返回的文件的路径为“/cache”。对于第三方应用程序。该目录下的文件是只读。第三方应用程序无法对该目录下的文件进行写操作。
public static File getRootDirectory ()
用File返回Android系统文件的根目录,返回的文件的路径为“/system”。该目录下的文件是只读。应用程序无法对该目录下的文件进行写操作。
Android中关于内部存储的一些重要函数的更多相关文章
- android中的内部存储与外部存储
我们先来考虑这样一个问题: 打开手机设置,选择应用管理,选择任意一个App,然后你会看到两个按钮,一个是清除缓存,另一个是清除数据,那么当我们点击清除缓存的时候清除的是哪里的数据?当我们点击清除数据的 ...
- 彻底了解android中的内部存储与外部存储
我们先来考虑这样一个问题: 打开手机设置,选择应用管理,选择任意一个App,然后你会看到两个按钮,一个是清除缓存,另一个是清除数据,那么当我们点击清除缓存的时候清除的是哪里的数据?当我们点击清除数据的 ...
- 彻底理解android中的内部存储与外部存储
我们先来考虑这样一个问题: 打开手机设置,选择应用管理,选择任意一个App,然后你会看到两个按钮,一个是清除缓存,另一个是清除数据,那么当我们点击清除缓存的时候清除的是哪里的数据?当我们点击清除数据的 ...
- 【转】彻底理解android中的内部存储与外部存储
我们先来考虑这样一个问题: 打开手机设置,选择应用管理,选择任意一个App,然后你会看到两个按钮,一个是清除缓存,另一个是清除数据,那么当我们点击清除缓存的时候清除的是哪里的数据?当我们点击清除数据的 ...
- Android SDCard和内部存储中gcc编译后的可执行文件无法运行提示 cannot execute - Permission denied
原因是mount的方式问题,root后运行 su mount -o rw,remount /mnt/sdcard //SDCard mount -o rw,remount /mnt/interna ...
- 67.Android中的数据存储总结
转载:http://mp.weixin.qq.com/s?__biz=MzIzMjE1Njg4Mw==&mid=2650117688&idx=1&sn=d6c73f9f04d0 ...
- Android笔记——Android中数据的存储方式(一)
Android中数据的存储方式 对于开发平台来讲,如果对数据的存储有良好的支持,那么对应用程序的开发将会有很大的促进作用. 总体的来讲,数据存储方式有三种:一个是文件,一个是数据库,另一个则是网络.其 ...
- Android中的数据存储
Android中的数据存储主要分为三种基本方法: 1.利用shared preferences存储一些轻量级的键值对数据. 2.传统文件系统. 3.利用SQLite的数据库管理系统. 对SharedP ...
- Android笔记——Android中数据的存储方式(二)
我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...
随机推荐
- servlet-有参数的init和无参的init方法
package gz.itcast.d_init; import javax.servlet.ServletConfig; import javax.servlet.ServletException; ...
- 一个有趣的 ”Validation of viewstate MAC failed” 错误的发现和解决
在ASP.NET里面,View State使用较为广泛.它作为一个隐藏字段,可以帮助服务端”记住“客户端的改变,这样客户端 收到服务器对PostBack的响应后,仍然可以展现在PostBack之前设定 ...
- 如何知道自己的CPU支持SLAT
因为WP8 SDK发布,很多WP8的开发者们也开始陆续安装WP8的SDK的,然而安装WP8的SDK有很多软件和硬件的要求,其中有一个就是——要求CPU支持二级地址转换(SLAT),如果CPU不支持二级 ...
- PHP 数据库连接 (Mysql Mysqli PDO)
1.PHP与Mysql扩展(本扩展自 PHP 5.5.0 起已废弃,并在将来会被移除),PHP原生的方式去连接数据库,是面向过程的 <?php $mysql_conf = array( 'hos ...
- elasticsearch学习(1)简单查询与聚合
elastic 被用作全文搜索.结构化搜索.分析以及这三个功能的组合 一个ElasticSearch集群可以包含多个索引, 每个索引包含多个类型 一个类型存储着多个文档 每个文档又有多个属性 索引(名 ...
- MySQL(端口3306)
MySQL(二进制)安装: 下载地址:http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz ...
- Huawei-R&S-网络工程师实验笔记20190530-FTP上传下载、STelnet登录、SFTP登录
>Huawei-R&S-网络工程师实验笔记20190530-FTP上传下载.STelnet登录.SFTP登录 >>实验开始,参考<Huawei-R&S-网络工程 ...
- random随机库
random库是用于产生并运用随机数的标准库 主要包含的有9个随机函数,分别是: seed(), random(), randint(), getrandbits(), randrange(), un ...
- Restful传递数组参数的两种方式
第一种,直接传递数组 js直接传递数组 var data = ["123","456"];that.loadDictionarys(data).subscrib ...
- 重庆OI2017 小 Q 的棋盘
小 Q 的棋盘 时间限制: 1 Sec 内存限制: 512 MB 题目描述 小Q正在设计一种棋类游戏.在小Q设计的游戏中,棋子可以放在棋盘上的格点中.某些格点之间有连线,棋子只能在有连线的格点之间移 ...