-
打印流
1. 打印流只有输出流没有输入流
2. 字节打印流和字符打印流都是包装流,字节打印流是 FilterOutputStream 类的子类
3. 打印流不仅可以打印在显示器上,根据构造函数传进来的参数指定打印到不同对象中去
-
PrintStream 类(字节打印流)
public class PrintStream01 {
public static void main(String[] args) throws IOException {
// 字节打印流
PrintStream out = System.out;
// 默认情况下, 打印流输出数据的位置是显示器
out.print("PrintStream Hello");
out.write("韩顺平, 你好".getBytes(StandardCharsets.UTF_8));
// 修改打印流打印的设备
System.setOut(new PrintStream("d:\\a.txt"));
// 修改默认输出设备后, 输出的就不是显示器, 而是规定的文件中
System.out.println("hello, 韩顺平教育! ");
out.close();
}
}
-
PrintWriter 类(字符打印流)
public class PrintWriter01 {
public static void main(String[] args) throws