程序中获得配置文件输入流和输出流的通用方法

    技术2022-05-11  57

     

    class ServiceConfig{

    private static Properties params = new Properties();

    public static void load() {

     

      InputStream is = ServiceConfig.class.getResourceAsStream(configFile);  try {   params.load(is);  } catch (Exception e) {   throw new RuntimeException("无法读取配置信息:" + e.getMessage());  } }

     public static void save() {  URL url = ServiceConfig.class.getResource(configFile);  try {   OutputStream os = new FileOutputStream(url.getFile());   params.store(os, null);  } catch (Exception e) {   throw new RuntimeException("无法将配置信息写入配置文件:" + e.getMessage());  }   }  }


    最新回复(0)