
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();
}
}