PrintStream(字节打印流)和PrintWriter(字符打印流),打印流-属于输出流->向控制台输出,类似于System.out,方便打印各种数据值表示形式,写的是样子,打印出来的就是什么样子
字节流
public static void main(String[] args) throws IOException {// TODO Auto-generated method stub//字节输出流FileOutputStream fos = new FileOutputStream("print.txt");PrintStream ps =new PrintStream(fos);ps.println("你好");ps.println("true");ps.println("哈哈");ps.append("你是最棒的");ps.flush();ps.close(); }
}
字符流
public static void main(String[] args) throws IOException {// TODO Auto-generated method stub//字节输出流FileWriter fos = new FileWriter("print11.txt");PrintWriter ps =new PrintWriter(fos);ps.println("你好gfgfdgdfgfd");ps.println("truen好地方和代发货");ps.println("哈哈");ps.append("你是最棒的");ps.flush();ps.close(); }
}