⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test6.java

📁 代码包括《Java语言与面向对象程序设计题解与实验指导》一书中 “习题解答”部分的所有程序的Java源代码和编译后生成的字节码或相应的HTML文件。 盘中的目录与书中的章节一致。
💻 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 + -