除了保存和/或加载数据之外,它会做所有需要做的事情。我假设问题出在加载上,即使 try/catch 没有异常。这些文件是由插件创建的,但它不会加载应该在关闭时保存的数据......
完整的课程可以在这里找到:http: //pastebin.com/pK3NCPfM
加载方法:
public void getClans(){
try {
// Load the Clans
FileInputStream f_in = new FileInputStream("Clans.data");
ObjectInputStream obj_in = new ObjectInputStream (f_in);
@SuppressWarnings("unchecked")
HashMap<String, Clan> Clans = (HashMap<String, Clan>) obj_in.readObject();
obj_in.close();
getLogger().info("Clans successfully loaded");
} catch (Exception e) {
getLogger().info("Error loading clan files...");
getLogger().info(e.getMessage());
}
}
public void getPlayers(){
try {
// Load the players that are in a clan
FileInputStream f_in = new FileInputStream("clanPlayers.data");
ObjectInputStream obj_in = new ObjectInputStream (f_in);
@SuppressWarnings("unchecked")
HashMap<String, String> clanPlayers = (HashMap<String, String>) obj_in.readObject();
obj_in.close();
getLogger().info("clanPlayers successfully loaded");
} catch (Exception e) {
getLogger().info("Error loading clanPlayer files...");
getLogger().info(e.getMessage());
}
}
更新:我不确定为什么这不起作用。如果有人可以帮助我修复有问题的线路,我应该很高兴!
public void getPlayers(){
try {
// Load the players that are in a clan
FileInputStream f_in = new FileInputStream("clanPlayers.data");
ObjectInputStream obj_in = new ObjectInputStream (f_in);
@SuppressWarnings("unchecked")
clanPlayers = (HashMap<String, String>) obj_in.readObject(); // Error on this line.
//I want the HashTable ClanPlayers to be a copy of the object that was saved
obj_in.close();
getLogger().info("clanPlayers successfully loaded");
} catch (Exception e) {
getLogger().info("Error loading clanPlayer files...");
getLogger().info(e.getMessage());
}
}