该程序要求输出文件名,似乎运行良好。直到我尝试使用文本编辑器或终端打开输出文件。然后我在该文件中看不到任何内容,只是空白文件。该程序创建文本文件,但文件为空。提前感谢您的帮助。
import java.util.*;
import java.io.IOException;
import java.io.PrintWriter;
/**
 * Writes a Memo file.
 * 
 */
public class MemoPadCreator {
  public static void main(String args[]) {
    Scanner console = new Scanner(System.in);
    System.out.print("Enter Output file name: ");
    String filename = console.nextLine();
  try {
    PrintWriter out = new PrintWriter(filename);
    boolean done = false;
    while (!done) {
      System.out.println("Memo topic (enter -1 to end):");
      String topic = console.nextLine();
      // Once -1 is entered, memo's will no longer be created.
      if (topic.equals("-1")) {
        done = true;
     console.close();
      }
      else {
        System.out.println("Memo text:");
        String message = console.nextLine();
        /* Create the new date object and obtain a dateStamp */
        Date now = new Date();
        String dateStamp = now.toString();
        out.println(topic + "\n" + dateStamp + "\n" + message);
      }
   }
    /* Close the output file */
  } catch (IOException exception) {
    System.out.println("Error processing the file:" + exception);
  }console.close();
  }
}