1 /**
2 * 保存文件
3 * @param filename 文件名称
4 * @param content 文件内容
5 */
6 public void save(String filename, String content) throws Exception {
7 //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
8 FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_PRIVATE);
9 outStream.write(content.getBytes());
10 outStream.close();
11 }
12
13 /**
14 * 保存文件
15 * @param filename 文件名称
16 * @param content 文件内容
17 */
18 public void saveAppend(String filename, String content) throws Exception {//ctrl+shift+y / x
19 //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
20 FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_APPEND);
21 outStream.write(content.getBytes());
22 outStream.close();
23 }
24
25 /**
26 * 保存文件
27 * @param filename 文件名称
28 * @param content 文件内容
29 */
30 public void saveReadable(String filename, String content) throws Exception {
31 //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
32 FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_WORLD_READABLE);
33 outStream.write(content.getBytes());
34 outStream.close();
35 }
36
37 /**
38 * 保存文件
39 * @param filename 文件名称
40 * @param content 文件内容
41 */
42 public void saveWriteable(String filename, String content) throws Exception {
43 //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
44 FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_WORLD_WRITEABLE);
45 outStream.write(content.getBytes());
46 outStream.close();
47 }
48
49 /**
50 * 保存文件
51 * @param filename 文件名称
52 * @param content 文件内容
53 */
54 public void saveRW(String filename, String content) throws Exception {
55 //私有操作模式:创建出来的文件只能被本应用访问,其它应用无法访问该文件,另外采用私有操作模式创建的文件,写入文件中的内容会覆盖原文件的内容
56 FileOutputStream outStream = context.openFileOutput(filename, Context.MODE_WORLD_WRITEABLE + Context.MODE_WORLD_READABLE);
57 outStream.write(content.getBytes());
58 outStream.close();
59 }