0
我正在寫這段代碼,並且不斷收到一個運行時錯誤,告訴我需要捕獲IOException。我怎麼做?這是我的代碼:如何捕獲reset()方法的IOException?
System.out.println("\nThese presidents were born before the states were formed:\n"); // DO NOT REMOVE OR MODIFY
ArrayList<String> america = new ArrayList<String>();
String l;
String line;
while((line = infile2.readLine()) != null)
{
america.add(line);
}
Collections.sort(america);
infile1.reset();
try
{
while((infile1.ready()))
{
ArrayList<String> am = new ArrayList<String>();
l= infile1.readLine();
String [] ls = l.split(" ");
for(int i=1; i<ls.length;i++)
{
am.add(ls[i]);
}
Collections.sort(am);
america.removeAll(am);
}
}
catch(IOException ex)
{
System.out.println("ERROR");
}
System.out.println(america);
通常,向我們展示您正在討論的堆棧跟蹤/錯誤輸出是個好主意。 –
什麼是infile1? –