VehicleType=com.potevio.zjx.study.Car
package com.potevio.zjx.study; import java.io.IOException; import java.util.Properties; /** *简单的读取配置文件信息 *@author Zhou-Jingxian */ public class Test { public static void main(String[] args) throws IOException { Properties props = new Properties(); props.load(Test.class.getClassLoader() .getResourceAsStream("com/potevio/zjx/study/study_pro.properties")); String vehicleTypeName = props.getProperty("VehicleType"); System.out.println("vehicle:"+vehicleTypeName); } }
Notice :
属性文件和测试类文件在同一个文件夹下