Javaでファイルを読み取る際に問題があります。私のファイルは次のとおりです。
3,4
2
6
4
1
7
3
8
9
ここで、最初の 3 行目と 4 行目は配列 A と B の長さで、次に各配列の要素です。私はこれを作りました
import java.io.*;
import java.util.Arrays;
public class Progetto {
public static void main(String args[])
{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("prova.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine = br.readLine(); // step 1
if (strLine != null) {
String[] delims = strLine.split(","); // step 2
// step 3
int[] a = new int[Integer.parseInt(delims[0])];
int[] b = new int[Integer.parseInt(delims[1])];
// step 4
for (int i=0; i < a.length; i++)
a[i] = Integer.parseInt(br.readLine());
// step 5
for (int i=0; i < b.length; i++)
b[i] = Integer.parseInt(br.readLine());
br.close(); // step 6
// step 7
System.out.println(Arrays.toString(a));
System.out.println(Arrays.toString(b));
}
}
}
しかし、それは私にエラーを与えます: -Unhandled exception type FileNotFoundException (line 11) -Unhandled exception type IOException (lines 15 26 30 32) しかし、理由はわかりません。誰かが私を助けることができます。前もって感謝します