1. First create a package (such as: config) in the project, then create a configuration file (such as: a.properties), and add the configuration information as follows:
for example:
Copy the code code as follows:
name=kaka
age=28
2. Code:
Copy the code code as follows:
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertyTest {
public static void main(String[] args) {
PropertyTest loadProp = new PropertyTest();
InputStream in = loadProp.getClass().getResourceAsStream("/config/a.properties");
Properties prop = new Properties();
try {
prop.load(in);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(prop.getProperty("name"));
System.out.println(prop.getProperty("age"));
}
}