博主前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住也分享一下给大家,
👉点击跳转到网站
数据流的概述:
DataInputStream 和 DataOutputStream
作用:用于读取或者写出基本数据类型或者字符串
@Test
public void test2(){
DataOutputStream dos = null;
try {
dos = new DataOutputStream(new FileOutputStream("demo.txt"));
dos.writeUTF("程序员");
dos.writeInt(30);
dos.writeBoolean(true);
}catch (Exception e){
e.printStackTrace();
}finally {
if (dos!=null) {
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Test
public void test3(){
DataInputStream dis = null;
try {
dis = new DataInputStream(new FileInputStream("demo.txt"));
String name = dis.readUTF();
int age = dis.readInt();
boolean isMale = dis.readBoolean();
System.out.println("name=" + name);
System.out.println("age=" + age);
System.out.println("isMale=" + isMale);
}catch (Exception e){
e.printStackTrace();
}finally {
if (dis!=null) {
try {
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}