我正在尝试在 Java 中实现银行家算法,但我无法加载我的数组。这是我正在使用的代码
public static void main(String[] args) throws FileNotFoundException {
String filename = null;
int need[][];
int allocate[][];
int max[][];
int available[][];
int n = 0;
int m = 0;
int lineCount = 0;
Scanner in = new Scanner(System.in);
System.out.println("Enter the file name.");
filename = in.nextLine();
File textFile = new File(filename);
Scanner input = new Scanner(textFile);
max = new int[n][m];
allocate = new int[n][m];
need = new int[n][m];
available = new int[1][m];
n = input.nextInt();
m = input.nextInt();
System.out.print("Number of Processes: " + n);
System.out.print("\nNumber of Processes: " + m);
max = new int[n][m];
allocate = new int[n][m];
need = new int[n][m];
available = new int[1][m];
String line = input.nextLine();
while (line != null && lineCount < n) {
String[] temp = line.split(" ");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
allocate[i][j] = Integer.parseInt(line);
System.out.println("here");
}
line = input.nextLine();
lineCount++;
}
}
}
我的示例文件包含此数据。
5
4
0 0 1 2 1 0 0 0 1 3 5 4 0 6 3 2 0 0 1 4
0 0 1 2 1 7 5 0 2 3 5 6 0 6 5 2 0 6 5 6
1 5 2 0
1:0 4 2 0
因此,在尝试执行此操作时,我遇到了许多不同的错误。现在我收到 NumberFormatException: For input string "" 错误。任何帮助深表感谢。