我無法弄清楚爲什麼我的代碼出現上述錯誤。每次調用方法時,我都會創建一個FileWriter和BufferedWriter的新實例,但顯然該流已經關閉。寫入文件:IOException:流關閉
public static void addSpawn(Location spawn)
{
File spawns = new File("spawns.dat");
FileWriter write = null;
BufferedWriter out = null;
try
{
write = new FileWriter(spawns, true);
out = new BufferedWriter(write);
out.write(locToStr(spawn));
out.newLine();
}
catch(Exception e)
{
System.out.println("Error writing spawn file: " + e.getMessage());
}
finally
{
if(write != null)
{
try
{
write.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
if(out != null)
{
try
{
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
任何幫助將不勝感激。
請顯示完整的堆棧跟蹤,包括指示您已發佈代碼中的哪一行引發異常。 – 2014-08-30 20:09:23