Android文件存储小结
2016-10-12 10:04
267 查看
核心技术就是Context类的openFileInput()和openFileOutput()方法,之后就是利用java的各种流进行读写操作。但是文件存储并不适用于保存一些比较复杂的文本数据。
典型结构:
典型结构:
/*存储*/ FileOutputStream out=null; PrintWriter pw=null; try{ out=openFileOutput("data",Context.MODE_PRIVATE); //可以看出openFileOutput方法返回的是FileOutputStream类型 pw=new PrintWriter(out); pw.write(inputText); pw.flush(); }catch(Exception e){ e.printStackTrace(); }finally{ try{ if(writer!=null){ writer.close(); } }catch(IOException e){ e.printStackTrace(); } }
/*读取*/ FileInputStream in=null; BufferedReader br=null; StringBuilder sb=new StringBuilder(); try{ in=openFileInput("data"); br=new BufferedReader(new InputSreamReader(in)); String temp=""; if((temp=br.readLine())!=null){ sb.append(temp); } }catch(IOException e){ e.printStackTrace(); }finally{ if(br!=null){ try{ br.close(); }catch(IOException e){ e.printStackTrace(); } } }
相关文章推荐
- android数据存储在文件小结
- 从J2EE转向Android的第九天-----文件存储
- Android数据存储之文件存储
- Android 中下载文件到sdcard和进度条小结
- Android数据存储之文件存储
- 【Android游戏开发十三】(保存游戏数据 [下文])详解SQLite存储方式,并把SQLite的数据库文件存储在SD卡中!!!
- Android数据存储之文件存储
- 【Android游戏开发十三】(保存游戏数据 [下文])详解SQLite存储方式,并把SQLite的数据库文件存储在SD卡中!!!
- Android数据存储操作②文件存储
- Android 文件以及属性文件存储
- android之使用文件进行数据存储
- android文件存储的4种方式
- Android 数据存储 之 使用文件进行数据存储
- Android数据存储之文件存储
- Android 中下载文件到sdcard和进度条小结
- Android的文件存储和访问
- 【Android游戏开发十三】(保存游戏数据 [下文])详解SQLite存储方式,并把SQLite的数据库文件存储在SD卡中!!!
- Android 数据存储和文件使用案例分析
- Android中的文件存储数据方式
- android使用文件进行存储