我需要以下我知道是错误的部分的帮助:
- 空格/截断 - 我不知道该怎么做
- file.seek - 可能是错误的,因为我没有将间距/截断为 8 个字符。
这是我的代码:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
public class NationalBank
{
public static void main(String[] args)
{
InputStreamReader temp = null;
BufferedReader input = null;
try
{
temp = new InputStreamReader(System.in);
input = new BufferedReader(temp);
int acct;
double amount[] = new double[9999];
String name[] = new String[9999];
RandomAccessFile file = new RandomAccessFile("bank.txt", "rw");
while(true)
{
System.out.println("Enter Account Number (0-9999): ");
acct = Integer.parseInt(input.readLine());
System.out.println("Enter Last Name: ");
name[acct] = input.readLine();
System.out.println("Enter Balance ");
amount[acct] = Double.parseDouble(input.readLine());
if(acct >=0 && acct <=9999) {
file.seek(acct*10);
file.writeBytes(" "+name[acct]);
file.writeBytes(" "+amount[acct]);
}
System.out.println("Enter More? (y/n)");
if (input.readLine().toLowerCase().equals("n"))
break;
}
file.close();
}
catch (Exception e)
{
}
}
}