程序的内存向持久化输出
在写入文件的时候 文件不存在会自动创建的
文件在写入的时候 默认是覆盖原文件
如果不想覆盖 而是想添加 那就在构造器后面加一个参数 true
//创建文件对象File file = new File("2.txt");//相对于当前项目路径//创建流FileWriter writer =null;try {writer =new FileWriter(file,true);} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}//写入String string = "我是斩杀大师大师大师看机会的卡仕达";//toCharArray() 将字符串转成字符数组try {writer.write(string.toCharArray());} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}finally {if (writer!=null) {try {writer.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
