2.2、读写二进制数据(DataInputStream/DataOutputStream)
package xyz.jangle.javabase.n2.b2;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import xyz.jangle.javabase.n2.b1.M3;
/**
* 2.2、读写二进制数据(DataInputStream/DataOutputStream)
* @author jangle
* @email jangle@jangle.xyz
* @time 2021年2月14日 上午7:38:16
*
*/
public class M1 {
public static void main(String[] args) throws IOException {
try(var dout = new DataOutputStream(Files.newOutputStream(Paths.get(M3.pathFileStr)))){
dout.writeUTF("你好啊");
dout.writeInt(123);
}
try(var din = new DataInputStream(Files.newInputStream(Paths.get(M3.pathFileStr)))){
String readUTF = din.readUTF();
System.out.println(readUTF);
int readInt = din.readInt();
System.out.println(readInt);
}
}
}