java DataInputStream和DataOutputStream详解及实例代码
程序员文章站
2024-03-07 13:34:57
java datainputstream和dataoutputstream详解
操作基本数据类型的流
datainputstream
dataoutput...
java datainputstream和dataoutputstream详解
操作基本数据类型的流
datainputstream
dataoutputstream
import java.io.datainputstream; import java.io.dataoutputstream; import java.io.fileinputstream; import java.io.fileoutputstream; import java.io.ioexception; public class integerdemo { public static void main(string[] args) throws ioexception { mywrite(); myreader(); } private static void mywrite() throws ioexception { // todo auto-generated method stub // 创建数据输出流对象 fileoutputstream fos = new fileoutputstream("e:\\zikao\\file\\cs.txt"); dataoutputstream dos = new dataoutputstream(fos); // 写数据 dos.writebyte(10); dos.writeshort(100); dos.writeint(1000); dos.writelong(10000); dos.writefloat(12.34f); dos.writedouble(12.56); dos.writechar('a'); dos.writeboolean(true); // 释放资源 dos.close(); } private static void myreader() throws ioexception { // todo auto-generated method stub // 创建数据输入流对象 fileinputstream fis = new fileinputstream("e:\\zikao\\file\\cs.txt"); datainputstream dis = new datainputstream(fis); // 读数据 byte b = dis.readbyte(); short s = dis.readshort(); int i = dis.readint(); long l = dis.readlong(); float f = dis.readfloat(); double d = dis.readdouble(); char c = dis.readchar(); boolean bl = dis.readboolean(); // 释放资源 dis.close(); system.out.println(b); system.out.println(s); system.out.println(i); system.out.println(l); system.out.println(f); system.out.println(d); system.out.println(c); system.out.println(bl); } }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!