1、创建config.properties文件
username=java
password=123
2、加载配置文件
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Test {
public static void main(String[] args) throws IOException {
Properties properties = new Properties();
InputStream inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("cn/java/learn07/config.properties");
properties.load(inStream);
System.out.println(properties.getProperty("username"));
System.out.println(properties.get("password"));
}
}
import java.util.ResourceBundle;
public class Test {
public static void main(String[] args) {
ResourceBundle bundle = ResourceBundle.getBundle("cn/java/learn07/config");
System.out.println(bundle.getString("username"));
System.out.println(bundle.getString("password"));
}
}