首页javastreamJava I/O - 如何直接从文件名创建文件输出流

Java I/O - 如何直接从文件名创建文件输出流

我们想知道如何直接从文件名创建文件输出流。
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class Main {
  public static void main(String[] a) {
    FileOutputStream outputFile = null; // Place to store the stream reference
    try {
      outputFile = new FileOutputStream("myFile.txt");
    } catch (FileNotFoundException e) {
      e.printStackTrace(System.err);
    }
  }
}