代码如下:
package PrintWriterPack;import java.io.FileNotFoundException;
import java.io.PrintWriter;public class PrintWriterDemo {public static void main(String[] args) throws FileNotFoundException {PrintWriter pw = new PrintWriter("D:\\JavaDemo\\pw.txt");pw.write("hello");pw.write("\r\n");pw.flush();pw.write("\r\n");pw.write("world");pw.flush();pw.close();}
}
package PrintWriterPack;import java.io.FileNotFoundException;
import java.io.PrintWriter;public class PrintWriterDemo {public static void main(String[] args) throws FileNotFoundException {PrintWriter pw = new PrintWriter("D:\\JavaDemo\\pw.txt");pw.println("hello");pw.flush();pw.println("world");pw.flush();pw.close();}}
package PrintWriterPack;import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;public class PrintWriterDemo {public static void main(String[] args) throws IOException {PrintWriter pw = new PrintWriter(new FileWriter("D:\\JavaDemo\\pw.txt"),true);pw.println("hello");pw.println("world");pw.close();}}