开发实用技术(个人备忘)-properties 文件读取工具类 PropertiesUtils

tech2026-02-19  2

1.代码: 

import java.io.IOException; import java.io.InputStream; import java.util.Properties; public class PropertiesUtils { public static Properties properties = null; public PropertiesUtils(String path) { InputStream inputStream = PropertiesUtils.class.getClassLoader().getResourceAsStream(path); properties = new Properties(); try { properties.load(inputStream); } catch (IOException e) { e.printStackTrace(); }finally{ if (null != inputStream){ try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static String getString(String key, String path){ if (null == properties){ new PropertiesUtils(path); } return properties.getProperty(key); } }

 

 2.测试

##图片上传路径 PATH=D:/upload_pic/ String upload_path = PropertiesUtils.getString("PATH", "config.properties");

 

最新回复(0)