打印流
PrintStream字节打印流
PrintWriter字符打印流
package IODemo;
import java.io.*;
/**打印流:很方便的进行输出
*字节打印流 PrintStream
* 字符打印流 PrintWriter
*
*/
public class PrintStreamDemo {
private static void bytePrint(){
File file = new File("D:\\测试\\我是大傻.txt");
try {
OutputStream os = new FileOutputStream(file );
//加缓存
BufferedOutputStream buf = new BufferedOutputStream(os);
//增强打印
PrintStream prs = new PrintStream(buf);
prs.println("今天又失眠了!\r\n");
prs.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private static void charPrint(){
File file = new File("D:\\测试\\我是大傻.txt");
try {
Writer wr = new FileWriter(file,true);
//加缓存
BufferedWriter bfw = new BufferedWriter(wr);
//增强打印
PrintWriter prs = new PrintWriter(bfw);
prs.println("今天又失眠了!\r\n");
prs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// bytePrint();
charPrint();
}
}