![这里写图片描述](https://img-blog.csdn.net/2018032702104245?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzQwNjYyMjgx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
package bull1713.PrintWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class PrintWriterDemo1 {
public static void main(String[] args) throws IOException {
method1();
method2();
}
private static void method2() throws IOException {
PrintWriter pw = new PrintWriter(new FileWriter("pwd.txt"),true);
pw.println("java");
pw.println("android");
pw.close();
}
private static void method1() throws FileNotFoundException {
PrintWriter pw = new PrintWriter("pwd.txt");
pw.println("hello");
pw.println("world");
pw.close();
}
}
package bull1713.PrintWriter;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class PrintWriterDemo2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("IODemo2.txt"));
PrintWriter pw = new PrintWriter(new FileWriter("pwd2.txt"),true);
String line;
while((line = br.readLine()) != null) {
pw.println(line);
}
br.close();
pw.close();
}
}