以后写数据就用打印流: 高效方便,直接打印到文件
PrintStream(字节输出流)、PrintWriter(字符流)没有区别,都一样
// 写数据会有区别,一个写字节,一个写字符 (但是打印流一般是用来打印的) 不要用write方法就没区别



打印流:直接打印到文件里面去


package com.itheima.d6_printStream;import java.io.FileOutputStream;import java.io.PrintStream;/*** 目标:学会使用打印流 高效方便 写数据到文件*/public class PrintDemo1 {public static void main(String[] args) throws Exception{// 1. 创建一个打印流对象 打印: 顾名思义:就是输出出来,用输出流// PrintStream ps = new PrintStream(new FileOutputStream("io-app2/src/ps.txt"));// 追加数据,在低级管道后面加True就可以实现追加 不能再路径后面加,true,会报错,要在定义的管道(对象)后面加true)PrintStream ps = new PrintStream(new FileOutputStream("io-app2/src/ps.txt",true));// 打印流 可以直接写要打印的 路径地址// PrintStream ps = new PrintStream("io-app2/src/ps.txt"); // 可以直接通向低级管道,和路径ps.println(97);ps.println('a');ps.println(23.3);ps.println(true);ps.println("我是打印流,是什么就打印什么");ps.close(); // 释放流}}
