package com.test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropUtil {
	private static PropUtil util = null;
	private static Properties pro = null;
	private static final String PROP_LOCATION = "/File.properties";
	
	
	private PropUtil() {

	}

	public static final PropUtil getInstance() {
		if (util == null) {
			try {
				load(PROP_LOCATION);
			} catch (IOException e) {
				e.printStackTrace();
			}
			return new PropUtil();
		}
		return util;
	}
	
	private static void load(String path) throws IOException{
		pro = new Properties();
		InputStream inStream = PropUtil.class.getResourceAsStream(path);
		pro.load(inStream);
	}
	
	public static String getValue(String key){
		if(pro == null && pro.isEmpty())
			return "";
		return pro.getProperty(key);
	}
	
	public static void main(String[] args) {
		System.out.println(PropUtil.getInstance().getValue("innet"));
	}
}

File.properties文件内容:

test=1
outnet=10.180.6.175
address=localhost

相关文章:

  • 2021-12-05
  • 2021-11-30
  • 2021-06-30
  • 2021-12-15
  • 2021-12-16
  • 2022-01-30
  • 2021-06-26
猜你喜欢
  • 2022-01-04
  • 2021-07-05
  • 2022-12-23
  • 2021-07-27
  • 2021-07-09
  • 2021-08-20
  • 2022-01-25
相关资源
相似解决方案