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

📄 idgenerator.java

📁 java版的数据结构的完全代码 免费提供了 学习数据结构的请下载
💻 JAVA
字号:
// Introduced in Chapter 17import java.io.*;/** Generates unique id numbers, even across multiple sessions. */public class IdGenerator {  /** File in which the next available id is stored. */  public static final File FILE = new File(BTree.DIR + "id");  /** Return the next available id number. */  public static int nextId() {    try {      int result;      if (FILE.exists()) {        ObjectInputStream in          = new ObjectInputStream(new FileInputStream(FILE));        result = in.readInt();      } else {        result = 0;      }      ObjectOutputStream out        = new ObjectOutputStream(new FileOutputStream(FILE));      out.writeInt(result + 1);      out.close();      return result;    } catch (IOException e) {      e.printStackTrace();      System.exit(1);      return 0;    }  }  public static void main(String[] args) {    System.out.println(nextId());  }}

⌨️ 快捷键说明

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