!!!!java
读取txt文件中的内容缓存
!!!向文件中写入内容-若是指定文件不存在,会被建立app
在main方法中使用if作判断,是否运行测试方法,测试方法有四个,FileOutputStream与FileWriter都是写入到txt文件,区别是后者先写在缓存,清缓存或者缓存已满才会最终把内容放入到txt中。测试
txt的按行、列读ui
http://blog.csdn.net/bestcxx/article/details/65446489spa
最后附上本身写的一个封装好的方法,能够直接使用,不会覆盖原文件(即末尾续接).net
package com.zhaowu.renwu2; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class FileUtil { public static void toFile (String content) { File file = null; FileWriter fw = null; file = new File("/home/acer/桌面/aaa"); try { if (!file.exists()) { file.createNewFile(); } fw = new FileWriter(file,true); fw.write(content);//向文件中复制内容 fw.flush(); } catch (IOException e) { e.printStackTrace(); }finally{ if(fw != null){ try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } } }