大家好,又见面了,我是你们的朋友全栈君。
/** * 通过BufferedWriter写入数据到a.txt的文件中 * * * 输出流 , 字符流,处理流 */ import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException;
public class Test { public static void main(String[] args) { FileWriter fw = null; BufferedWriter bw = null; try { fw = new FileWriter(“d://a.txt”); bw = new BufferedWriter(fw); bw.write(“你猜我猜不猜”); bw.newLine(); //下一行 bw.write(“我不知道”); bw.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/135589.html原文链接:https://javaforall.cn