首页javawriterJava I/O - 如何从文件名创建PrintWriter

Java I/O - 如何从文件名创建PrintWriter

我们想知道如何从文件名创建PrintWriter。
 

import java.io.IOException;
import java.io.PrintWriter;

public class MainClass {
  public static void main(String[] args) {
    try {
      PrintWriter pw = new PrintWriter("c:\\temp\\printWriterOutput.txt");
      pw.println("PrintWriter is easy to use.");
      pw.println(1234);
      pw.close();
    } catch (IOException e) {
    }
  }
}