文件模式:
1.Context.MODE_PRIVATE:私有覆盖模式 - rw- rw- --- 只能被当前应用访问,并且如果写入,则覆盖;
2.Context.MODE_APPEND:私有追加模式 - rw- rw- --- 只能被当前应用访问,并且如果写入,则追加;
3.Context,MODE_WORLD_READABLE:公有只读模式 - rw- rw- r-- 可以被其他应用读取;
4.Context.MODE_WORLD_WRITEABLE:公有可写模式 - rw- rw- -w- 可以被其他应用写入,但不能读取;
注意,如果希望其他使得文件模式叠加,则可以使用加号连接;
比如:Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE 表示其他应用读写;
位置:
内和外
区别在于存储位置不同
内:默认 /data/data/package/files/
外:/sdcard 或 /mnt/sdcard 视版本 (使用 Environment.getExternalStorageDirectory() 获取)
流:
区别在于流实例类型 和 路径
//内:读写
FileOutputStream out = openFileOutput(FileName, MODE);
out.write(byte);
FileInputStream in = openFileInput(FileName);
ByteArrayOutputStream bout = new ByteArrayOutputStream ();
while ((length = in.read(buf)) != -1) {
bout.write(buf, 0, length);
}
byte[] fileContent = bout.toByteArray();
//外:读写
File file = new File(Environment.getExternalStorageDirectory(),FileName);
out = new FileOutputStream(file,true);
File file = new File(Environment.getExternalStorageDirectory(),FileName);
in = new FileInputStream(file);
注意:在使用外卡时,需要注意外卡的存储状态,加上使用权限
扩展:andoird如何打开不同类型的文件 http://zengyan2012.iteye.com/blog/1646492