test6.java
来自「各种关于JAVA的初级编程」· Java 代码 · 共 47 行
JAVA
47 行
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 + =
减小字号Ctrl + -
显示快捷键?