📄 exercise16_3.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(); DataInputStream dis = null; int count = 0; try { 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 { if (dis != null) dis.close(); } catch (IOException ex) { System.out.println(ex); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -