📄 test6.java
字号:
import java.io.*;
public class test6
{
public static void main(String args[])
{
try
{
DataOutputStream dout = new DataOutputStream(
new FileOutputStream("MyBinaryFile"));
for(int j=0; j<6; j++)
{
dout.writeUTF("星期" + j);
dout.writeDouble(30 + j); // 最高温度
dout.writeDouble(20 + j); // 最低温度
dout.writeBoolean( j%2==1 ? true : false); //是否降雨
}
dout.close();
DataInputStream din = new DataInputStream(
new FileInputStream("MyBinaryFile"));
try
{
for(;true;)
{
System.out.print(din.readUTF() + "\t");
System.out.print("最高温度:" + din.readDouble() + "\t");
System.out.print("最低温度" + din.readDouble() + "\t");
System.out.println(((din.readBoolean()) ? "有" : "无") + "降雨");
}
}
catch(EOFException eofe)
{
din.close();
}
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -