exercise16_3.java
来自「一款用java编写的小型数据库管理系统」· Java 代码 · 共 59 行
JAVA
59 行
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 + =
减小字号Ctrl + -
显示快捷键?