私は先週、このばかげたコードを機能させる方法を見つけようとしました。テキストファイルからの読み取りを除いて、すべてを機能させることができました。行の個々の整数を読み取ることができますが、スペースで区切られた複数の整数を含む行が指定されると、異常になります。今、私はそれを修正しようとしましたが、コードはもうコンパイルさえしません。1行だけが問題を引き起こしています。私はコーディングが苦手なので、どこから始めればよいかわかりません。はい、私はこれをオンラインで調べました。はい、フォーラムを確認しました。はい、これを機能させるために複数の異なる方法を試しました....どうすれば修正できますか?? :(
ArrayList<Integer> list = new ArrayList<Integer>();
// the above line is in a different method in the same class, but it's relevant here
File file = new File("C:\\Users\\Jocelynn\\Desktop\\input.txt");
BufferedReader reader = null;
try
{
reader = new BufferedReader(new FileReader(file));
String text = null;
while ((text = reader.readLine()) != null)
{
// I want the following line to read "218 150 500 330", and to store each individual integer into the list. I don't know why it won't work :(
list.add(Integer.parseInt(src.next().trim()));
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
reader.close();
}
catch (IOException e)
{
e.printStackTrace();
}
//print out the list
System.out.println(list);
お手伝いありがとう!本当に単純なものが欠けていると確信しています...