进阶之路--数据存储方式--file
2015-06-07 14:14
316 查看
文件:
1、采用私有模式创建文件:
1、采用私有模式创建文件:
//只能被本应用使用,私有操作模式,覆盖模式,默认路径:data/data/com.example.filesave/files String filename_withoutpath = "hello.txt"; byte[] bytearray = filename_withoutpath.getBytes(); try { FileOutputStream fos = context.openFileOutput(filename_withoutpath , MODE_PRIVATE); fos.write(bytearray); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { byte[] newbytearray = new byte[1024]; ByteArrayOutputStream output = new ByteArrayOutputStream(); FileInputStream fis = context.openFileInput(filename_withoutpath); int len = 0; while((len = fis.read(newbytearray))!= -1){ output.write(newbytearray, 0, len);//读进内存中 } byte[] content = output.toByteArray(); String content1 = new String(content); fis.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }2、追加操作模式:
FileOutputStream fos = context.openFileOutput(filename_withoutpath , MODE_APPEND);
相关文章推荐
- 慎用memset();
- 《算法导论》读书笔记之排序算法—Merge Sort 归并排序算法
- 由电影Matrix(骇客帝国)联想到的操作系统知识
- Chart图表在Android开发中的应用
- 注册——SIP学习笔记(六)
- 算法-链表实现栈
- Oracle复习重点
- RESTDebugger-我们的REST调试工具!!
- Android 虚拟机学习总结Dalvik虚拟机介绍
- RESTDebugger-我们的REST调试工具!!
- eclipse Maven 配置
- 调整数组顺序使奇数位于偶数前面
- 关于marked数组处理
- 排序应用--归并排序
- Struts2中的ModelDriven机制及其运用
- hdu 1104 Remainder 队列
- 寻找数列中的1
- hdu 1104 Remainder 队列
- Android Studio如何导入Github上的项目
- ubuntu下安装配置JDK