readrandom.java
来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 31 行
JAVA
31 行
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 + =
减小字号Ctrl + -
显示快捷键?