import java.io.*; /** * 1. 字符打印流 * 2. 缓存读取流 */ public class PrintAndBufferReader { public static void main(String[] args) throws IOException { // 字符输出(打印流) // System.out.println(); // PrintStream printStream = new PrintStream("/Users/christopoher/Desktop/poemFile"); // printStream.println("天下无双,前无古人"); // 字节与字符流区别在于是否刷新管道 字符要刷新或者关闭 PrintWriter printWriter = new PrintWriter("/Users/christopoher/Desktop/poemFile"); printWriter.println("天下无双,前无古人。"); printWriter.println("天下无双,前无古人, 后无来者。"); //printWriter.flush(); printWriter.close(); // 字节读取转换为字符 (记得flush或者close) FileOutputStream fileOutputStream = new FileOutputStream("/Users/christopoher/Desktop/poemFile");//字节读取 PrintWriter pw = new PrintWriter(fileOutputStream);//转为字符打印流 pw.println("送礼就送脑白金1"); pw.println("送礼就送脑白金2"); pw.close(); //缓存读取流,将字符输入流 转换为带有缓存 可以一次读取一行的缓存字符读取流 FileReader fileReader = new FileReader("/Users/christopoher/Desktop/poemFile"); BufferedReader bufferedReader = new BufferedReader(fileReader); String txt = bufferedReader.readLine(); System.out.println(txt); } }
IO简化概述IV
最新推荐文章于 2024-08-15 14:47:41 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)