public class AAA
{
private String a;
private String b;
public String getA()
{
return a;
}
public void setA(String a)
{
this.a = a;
}
public String getB()
{
return b;
}
public void setB(String b)
{
this.b = b;
}
}
public AAA read(final String path) {
File file = new File(path);
if (file.exists()) {
try {
XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
AAA a = (AAA) decoder.readObject();
return a;
} catch (FileNotFoundException e) {
log.error("加载配置信息异常:" + file.getPath(), e);
throw new RuntimeException("加载配置信息失败:" + e.getMessage());
}
} else {
throw new RuntimeException("找不到系统配置文件:" + file.getPath());
}
}
public void save(AAA a, final String path) {
File file = new File(path);
try {
XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file));
encoder.writeObject(a);
encoder.close();
} catch (Exception e) {
log.error("保存配置文件异常:" + file.getPath());
throw new RuntimeException("保存配置文件失败:" + e.getMessage());
}
}