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

📄 readrandom.java

📁 《A first book of java》by Gary J.Bronson 北大出版社
💻 JAVA
字号:
import java.io.*;
public class ReadRandom
{
  public static void main(String[] args)
    throws java.io.IOException
  {
    String fileName = "products.dat";
    int acct, amt;
    double price;
       
      // set up the basic random access input/output stream
    RandomAccessFile raf = 
        new RandomAccessFile(fileName, "rw");

      // print the headings
    System.out.println("          Quantity");
    System.out.println("ID. No.   In Stock   Price");
    System.out.println("-------   --------   ------");   

      // read and print the data
    for(int i = 1; i <= 5; i++)
    {
      acct = raf.readInt();    
      amt = raf.readInt();      
      price = raf.readDouble();
      System.out.println(" " + acct + "       " + amt + "      $" + price);
    }

    raf.close(); 
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -