1
3つのCSVファイルに数字の列でリンクされたデータがあり、2次元配列を作成してすべてのデータをまとめて保存し、csvファイル、他のファイルのデータは同じ順序ではないので、ファイルの第1行を配列の最初の行に読み込むことはできません。ファイルから並べ替えられた項目を配列に入れよう
は、ここで私はそれの多くは非常に整頓や効率的ではないことを知っている私のコード
public class grades {
public static void main(String[] args) throws FileNotFoundException
{
int rowc = 0;
String inputLine = "";
String[][] students = new String[10][6];
//Get scanner instance
Scanner scanner = new Scanner(new File("/IRStudents.csv"));
//Set the delimiter used in file
scanner.useDelimiter(",");
while (scanner.hasNextLine()) {
inputLine = scanner.nextLine();
String [] line = inputLine.split(",");
for (int x = 0; x < 2; x++) {
students[rowc][x] = line[x];
}
if (rowc < 9) {
rowc++;
}
else {
break;
}
}
System.out.println(Arrays.deepToString(students));
scanner.close();
Scanner input = new Scanner(new File("/IR101.csv"));
input.useDelimiter(",");
while (input.hasNext()) {
inputLine = input.nextLine();
String[] line = inputLine.split(",");
for (int i = 0; i < 1; i++) {
System.out.println(line[0]);
System.out.println(students[0][i]);
if (line[0].equals(students[0][i])) {
students[2][i] = line[0];
}
}
}
System.out.println(Arrays.deepToString(students));
}
}
だが、私はむしろそれが働いていたと思います。とにかく、どのようにファイルをループし、対応する文字列がリンクしている配列の3番目の列に各項目を追加しますか?
ありがとうございました。
あなたはCSVリーダーを使用する必要があるとないスキャナはあなたのコードを見クリーナーを行います。 – StackFlowed