首页 > 代码库 > Java_io_DataInputStream和DataOutputStream
Java_io_DataInputStream和DataOutputStream
节点流:可以直接创建的流
过滤流:可以装饰节点流,增加相应的功能,BufferedInputStream,DataOutputStream
package stream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class TestWriteNum {
public static void main(String[] args) {
FileOutputStream fos=null;
DataOutputStream dos=null;
DataInputStream dis=null;
//输出数字,读取数字
try {
fos=new FileOutputStream("D:\\JAVA SE\\temp\\num.dat");
dos=new DataOutputStream(fos);
dos.writeInt(456789123);
dis=new DataInputStream(new FileInputStream("D:\\JAVA SE\\temp\\num.dat"));
int a=dis.readInt();
System.out.println(a);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(dos!=null)
try {
dos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Java_io_DataInputStream和DataOutputStream