(1) 往当前目录下“test.dat”的文件中写入一个 long 类型的数值:10000L
(2) 从该文件中读出数值,并把该数值加 1 之后,再存回文件中。
package io.homework; import java.io.*; public class q19 { public static void main(String[] args) { try(OutputStream os = new FileOutputStream("test.dat"); DataOutputStream dos = new DataOutputStream(os); InputStream is = new FileInputStream("test.dat"); DataInputStream dis = new DataInputStream(is)) { dos.writeLong(10000L); long n = dis.readLong(); System.out.println(n); dos.writeLong(n+1); long l = dis.readLong(); System.out.println(l); }catch (Exception e) { e.printStackTrace(); } } }
注意 DataInputStream 只能读取当前DataOutputStream的写入数据
标签:字节,long,dat,过滤,DataOutputStream,test,new,Data,DataInputStream From: https://www.cnblogs.com/zuamagee/p/17300442.html