此文章是我工作中遇到讀取properties文件的問(wèn)題,然后寫(xiě)下與大家分享,如果大家有什么問(wèn)題,歡迎聯(lián)系我,互相探討。
測(cè)試類(lèi)
package com.test;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.Properties;
public class Test {
? ? /**
?? ? *讀取項(xiàng)目src下的properties文件
?? ? */
? ? public static void main(String[]args)throws ParseException {
? ? ? ? Properties prop = new Properties();
? ? ? ? InputStream in = Object.class.getResourceAsStream("/stand.properties");
? ? ? ? try {
? ? ? ? ? ? prop.load(in);
? ? ? ? ? ? String hegestand =(String)prop.get("hegestand");
? ? ? ? ? ? String jiyoustand =(String)prop.get("jiyoustand");
? ? ? ? ? ? System.out.println("hegestand:"+hegestand+",jiyoustand:"+jiyoustand);
? ? ? ? ? ? in.close();
? ? ? ? } catch(IOException e){
? ? ? ? ? ? e.printStackTrace();
? ? ? ? }
? ? }
}
輸出:
hegestand:30000,jiyoustand:60000
stand.properties文件
hegestand=30000
jiyoustand=60000