少し前に質問を投稿しましたが、回答があり、とても助かりました。久しぶりの投稿失礼します。=/
私はこれを調べましたが、何が間違っていたのかわかりません.印刷された結果はいくつかの「null」単語です. メソッドを使用して、テキスト ファイルのデータを 2 次元配列に取り込もうとしています。次に、そのメソッドをメイン クラスで実行して、入力された配列を出力します。
どんな助けでも大歓迎です、事前に感謝します。=)
メインクラス:
public static void main(String[] args) throws IOException {
ScoreProcessor scores = new ScoreProcessor();
String[][] table = scores.readFile();
for (int row = 0; row < table.length; row++) {
for (int col = 0; col < table[row].length; col++) {
System.out.print(table[row][col] + "\t");
}
}
}
メソッドを含む別のクラス:
public class ScoreProcessor {
static public String[][] readFile() throws IOException {
File filedata = new File("src/JavaApp2/Data.txt");
Scanner file = new Scanner(filedata);
int row = 0, col = 0;
String[][] scores = new String[8][5];
while (file.hasNext()) {
Scanner readfile = new Scanner(filedata);
readfile.nextLine();
readfile.useDelimiter(",");
while (readfile.hasNext(",")) {
String line = readfile.next();
line = scores[row][col] ;
col++;
} // end innerloop
row++;
col = 0;
} // end outerloop
return scores;
} // end method
} // end class
データファイル
Student,Q1,Q2,Q3,Q4
abcd0001,50,55,59,72
efgh0002,82,78,84,86
ijkl0003,42,45,46,52
mnop0004,66,74,72,78
qrst0005,82,86,89,88
uvwx0006,77,83,87,82
yzab0007,62,64,70,68