1. 程式人生 > 其它 >讀取*.properties檔案的配置資訊

讀取*.properties檔案的配置資訊

技術標籤:java

FileName:配置檔案的檔名(帶字尾)
key:想要讀取配置檔案中的關鍵字key(如下圖紅框中的key)

	public static String GetValues(String FileName, String key) throws IOException {
		Properties properties = new Properties();
		// 使用InPutStream流讀取properties檔案
		String path = RuntimeEnv.getInstance().getNCHome() + File.separator + "resources" + File.separator
				+ "gytzconfig" + File.separator + FileName;
		BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
		properties.load(bufferedReader);
		// 獲取key對應的value值
		return String.valueOf(properties.getProperty(key));
	}

在這裡插入圖片描述