Java读取配置文件

public class properties1 {

public static void getPro() {

InputStream iStream = properties1.class.getClassLoader().getResourceAsStream(“com/test1/www/mysql.properties”);

Properties properties = new Properties();

try {

properties.load(iStream);

String url = properties.getProperty(“url”);

String user = properties.getProperty(“user”);

String pass = properties.getProperty(“pass”);

String driver = properties.getProperty(“driver”);

System.out.println(url);

System.out.println(user);

System.out.println(pass);

System.out.println(driver);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static void main(String[] args) {

getPro();

}

}

PS:包名 .换成/

你可能感兴趣的:(Java读取配置文件)