posts - 570,  comments - 96,  views - 171万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
复制代码
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());
        }
    }
复制代码

 

posted on   你不知道的浪漫  阅读(121)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示