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

📄 exercise16_3.java

📁 一款用java编写的小型数据库管理系统
💻 JAVA
字号:
import java.io.*;public class Exercise16_3 {  public static void main(String[] args) throws IOException {    DataOutputStream output =      new DataOutputStream(new FileOutputStream("Exercise16_3.dat"));    for (int i = 1; i <= 100; i++)      output.writeInt(i);    output.close();  // Declare data input and output streams      DataInputStream dis = null;      // Read data      int count = 0;      try {        // Create data input stream        dis = new DataInputStream(new FileInputStream("Exercise16_3.dat"));        int total = 0;        while (dis.available() > 0) {          int temp = dis.readInt();          total += temp;          count++;          System.out.print(temp + " ");        }        System.out.println("\nCount is " + count);        System.out.println("\nTotal is " + total);      }      catch (FileNotFoundException ex) {        System.out.println("File not found");      }      catch (IOException ex) {        System.out.println(ex.getMessage());      }      finally {        try {          // Close files          if (dis != null) dis.close();        }        catch (IOException ex) {          System.out.println(ex);        }    }  }}

⌨️ 快捷键说明

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