PrintStream 和 PrintWriter
PrintStream
package com.ftn.printStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
public class PrintStream_ {
public static void main(String[] args) throws IOException {
PrintStream out = System.out;
out.println("打印一次");
out.write("aaa".getBytes(StandardCharsets.UTF_8));
System.setOut(new PrintStream("d:\\m1.txt"));
System.out.println("hello,hell");
out.close();
}
}
PrintWriter
package com.ftn.printStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class PrintWriter_ {
public static void main(String[] args) throws IOException {
PrintWriter printWriter = new PrintWriter(System.out);
printWriter.print("hhh");
PrintWriter printWriter1 = new PrintWriter(new FileWriter("d:\\t1.txt"));
printWriter1.print("hehehe");
printWriter.close();
printWriter1.close();
}
}