openFileOutput 文件属性设置、主动配置文件的可读写属性及其实现方式
来源:互联网 发布:counter python 编辑:程序博客网 时间:2024/06/03 21:24
首先参考
Android 内部存储相关的函数(getCacheDir,getDir, getFileStreamPath,getFilesDir,openFileInput, ...)
1. 用openFileOutput方法改变文件的属性,但是该方法有局限性,他创建的文件只能位于该程序的私有目录下,即/data/data/app-package/files/。
FileOutputStream fos; fos = openFileOutput("filename", MODE_WORLD_READABLE);
FileOutputStream android.content.ContextWrapper.openFileOutput(String name, int mode) throwsFileNotFoundException
Open a private file associated with this Context's application package for writing. Creates the file if it doesn't already exist.
可用的mode 参数如下:
/**
* File creation mode: the default mode, where the created file can only
* be accessed by the calling application (or all applications sharing the
* same user ID).
* @see #MODE_WORLD_READABLE
* @see #MODE_WORLD_WRITEABLE
*/
public static final int MODE_PRIVATE = 0x0000;
/**
* File creation mode: allow all other applications to have read access
* to the created file.
* @see #MODE_PRIVATE
* @see #MODE_WORLD_WRITEABLE
*/
public static final int MODE_WORLD_READABLE = 0x0001;
/**
* File creation mode: allow all other applications to have write access
* to the created file.
* @see #MODE_PRIVATE
* @see #MODE_WORLD_READABLE
*/
public static final int MODE_WORLD_WRITEABLE = 0x0002;
/**
* File creation mode: for use with {@link #openFileOutput}, if the file
* already exists then write data to the end of the existing file
* instead of erasing it.
* @see #openFileOutput
*/
public static final int MODE_APPEND = 0x8000;
最终的实现方式剖析:
最终还是调用了系统的chmod来实现的改变文件权限的功能。
Runtime.getRuntime().exec("chmod 644 " + filename);
2. 用Runtime.getRuntime().exec()调用系统命令chmod来改变文件的权限,为了能判断命令的返回值,最好写成:
- openFileOutput 文件属性设置、主动配置文件的可读写属性及其实现方式
- 让div可编辑,设置标签的可读可写属性
- android 平台自定义可读写的ro属性
- Samba服务器实现匿名用户可读可写的实现
- 灵活使用ACL设置samba的共享权限(user1可读写,user2可读不可写,user3可写不可读,user4只能看到共享!)
- 数组的length属性可读可写,字符串的长度length属性不可以修改
- 文件属性的设置
- 修改tomcat编码和设置可读写
- Swift类中如何创建一个对外只读对内可读写的属性
- 写可读的代码,代码不可读就是杯具
- SQLite 引用属性 文件属性如何设置!?
- Ubuntu下Samba服务器的简单设置,只读,可读写等权限控制。
- 由最简单的一个例子说起,匿名用户可读可写的实现(LINUX)配置
- android 系统获取可读写的方法
- Python之可读写的socket逻辑
- socket可读,可写的条件
- socket可读,可写的条件
- 使用VirtualAlloc()创建虚拟内存,修改可读、可写属性
- 爆笑:GIF 动画展示开发者的生活
- hdu 1160 FatMouse's Speed
- hdu 2674 N!Again(找规律)
- hdu-2709-Sumsets
- iOS 动画实现和理解
- openFileOutput 文件属性设置、主动配置文件的可读写属性及其实现方式
- LFS之(2)建立新用户和新环境
- JS实现定制右键默认操作的方法
- UNIX网络编程卷一:套接字联网API-整理
- C++中各运算符重载
- C语言的数组初始化
- 求奇偶子回文串个数
- 删除U盘里隐藏的文件
- 【暮色天】非农略显平淡 谨防反弹修复(8.4)