⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filer.java

📁 Java经典例程 从外国一大学计算机教授出版物下载的代码 经典
💻 JAVA
字号:
package myutilities;

import java.io.*;
import javagently.*;

public class Filer {

  /* The Filer class           by J M Bishop  June 2000
   * ----------------------    Java 1.2
   *                           based on the FileMan class
   *                           from June 1997
   *
   * Provides for a file to be opened, with five tries at a
   * correct file name.
   * Illustrates the use of exceptions in for-try loops..
   */

 public static Stream open (String filename) throws IOException {

    Stream in = new Stream (System.in);

    for (int count = 0; count < 5; count ++) {
      try {
        return new Stream(filename, Stream.READ);
      } catch (FileNotFoundException e) {
          System.out.println(filename+" does not exist.");
          if (count < 4) {
            System.out.println("Try again");
          }
          filename = in.readString();
      }
    }
    throw new FileNotFoundException ();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -