datastream.java~2~
来自「java2参考大全上的例子的源码和自己的理解.」· JAVA~2~ 代码 · 共 48 行
JAVA~2~
48 行
package datainput_output;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.io.*;
class DataStream {
public static void main(String args[]) throws IOException {
FileOutputStream fos = new FileOutputStream("DataStream.txt");
DataOutputStream dos = new DataOutputStream(fos);
try {
dos.writeBoolean(true);
dos.writeByte( (byte) 123);
dos.writeChar('J');
dos.writeDouble(3.141592654);
dos.writeFloat(2.7182f);
dos.writeInt(1234567890);
dos.writeLong(998877665544332211L);
dos.writeShort( (short) 11223);
}
finally {
dos.close();
}
DataInputStream dis = new DataInputStream(
new FileInputStream("DataStream.txt"));
try {
System.out.println("\t " + dis.readBoolean());
System.out.println("\t " + dis.readByte());
System.out.println("\t " + dis.readChar());
System.out.println("\t " + dis.readDouble());
System.out.println("\t " + dis.readFloat());
System.out.println("\t " + dis.readInt());
System.out.println("\t " + dis.readLong());
System.out.println("\t " + dis.readShort());
}
finally {
dis.close();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?