下面的代码遇到了java.util.ConcurrentModificationException
. 有什么办法可以防止或允许这种情况发生吗?
public void saveHomes() throws IOException {
BufferedWriter br;
br = new BufferedWriter(new FileWriter(homeFile));
Map<String, Location> homesLoc;
System.out.println(homes2.keySet());
for (String player : homes2.keySet()) {
homesLoc = homes2.get(player);
for (String name : homesLoc.keySet()) {
br.write(player + " " + homesLoc.get(name) + " " + name);
br.newLine();
br.flush();
}
}
br.close();
}