PropertiesTest
import java.io.FileInputStream; import java.io.IOException; import java.util.Properties; public class PropertiesTest { public static Properties getConf(String filename){ Properties prop = new Properties(); try { //prop.load(PropertiesTest.class.getClassLoader().getResourceAsStream("config.properties")); //放在bin/下 prop.load(new FileInputStream(filename)); //放在项目根目录 /*System.out.println(prop.getProperty("database")); System.out.println(prop.getProperty("dbuser")); System.out.println(prop.getProperty("dbpassword"));*/ } catch(IOException e) { e.printStackTrace(); } return prop; } public static void main(String[] args) { Properties prop = getConf("config.properties"); } }