📄 readrandom.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 + -