打印流概述及简单方法应用
打印流
宇节流打印流
PrintStream
字符打印流
Printwriter
打印流的特点:
A:只有写数据的,没有读取数据。只能操作目的地,不能操作数据源。
B:可以操作任意类型的数据。
C:如果启动了自动刷新,能够自动刷新。
D:该流是可以直按操作文本文件的。
哪些流对象是可以直接操作文本文件的呢?
FileInputStream
Fi leOutputStream
FileReader
FileWriter
Printstream
Printwriter
看API,查流对象的构造方法,如果同时有Fil e类型和Str ing类型的梦数,一般来说就是可以直接操作文件的。
流:
基本流:就是能够直接读写文件的
高级流:在基本流基础上提供了一些其他的功能
package cn.study_03;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.PrintWriter;
//字节流打印流
// Printstream
// 字符打印流
// Printwriter
public class PrintWriteDemo {
public static void main(String[] args) throws FileNotFoundException {
PrintWriter pw=new PrintWriter("pw.txt");
pw.write("helloword");
pw.write("helloword");
pw.write("helloword");
pw.close();
}
}