idea鎬庝箞璇诲彇properties鏂囦欢
鍦↗ava涓紝鍙互浣跨敤Properties
绫绘潵璇诲彇properties鏂囦欢銆備笅闈㈡槸涓€涓畝鍗曠殑渚嬪瓙锛?/p>
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class ReadPropertiesFile {
public static void main(String[] args) {
Properties properties = new Properties();
try {
FileInputStream file = new FileInputStream("config.properties");
properties.load(file);
file.close();
} catch (IOException e) {
e.printStackTrace();
}
String value1 = properties.getProperty("key1");
String value2 = properties.getProperty("key2");
System.out.println("Value for key1: " + value1);
System.out.println("Value for key2: " + value2);
}
}
鍦ㄤ笂闈㈢殑渚嬪瓙涓紝鎴戜滑鍒涘缓浜嗕竴涓?code>Properties瀵硅薄锛岀劧鍚庝娇鐢?code>FileInputStream鏉ュ姞杞絧roperties鏂囦欢銆傛帴鐫€浣跨敤load
鏂规硶灏嗘枃浠朵腑鐨勫睘鎬у姞杞藉埌Properties
瀵硅薄涓€傛渶鍚庡彲浠ラ€氳繃getProperty
鏂规硶鑾峰彇灞炴€х殑鍊笺€?/p>
闇€瑕佹敞鎰忕殑鏄紝瑕佺‘淇?code>config.properties鏂囦欢瀛樺湪骞朵笖浣嶄簬姝g‘鐨勮矾寰勪笅銆?/p>