数据流目的,操作基本变量和String类型进行持久化操作
import java.io.*;
/**
* @auto dh
* @create 2020-04-24-17:34
*/
public class File006 {
public static void main(String[] args) {
DataOutputStream ds = null;
DataInputStream di = null;
try {
ds = new DataOutputStream(new FileOutputStream("D:" + File.separator + "ac.txt"));
di = new DataInputStream(new FileInputStream("D:" + File.separator + "ac.txt"));
ds.writeUTF("张无忌");
ds.write(24);
String name=di.readUTF();
int age=di.read();
System.out.println("name: "+name);
System.out.println("age: "+age);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ds != null) {
try {
ds.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(di!=null){
try {
di.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}