-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPropDemo.java
More file actions
28 lines (25 loc) · 1.05 KB
/
PropDemo.java
File metadata and controls
28 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* Created with IntelliJ IDEA.
* User: Loon
* Date: 13-3-30
* Time: 下午5:13
* To change this template use File | Settings | File Templates.
*/
public class PropDemo {
public static void main(String[] args) throws IOException {
// InputStream inputStream = new FileInputStream(ClassLoader.getSystemResource("")+"\\com\\loon\\util\\person.properties");
// InputStream inputStream = new FileInputStream(PropDemo.class.getResource("")+"person.properties");
InputStream inputStream = PropDemo.class.getResourceAsStream("person.properties");
// InputStream inputStream = new FileInputStream("person.properties");
Properties properties = new Properties();
properties.load(inputStream);
String name = properties.getProperty("name");
String age = properties.getProperty("age");
String gender = properties.getProperty("gender", "male");
System.out.println(name);
System.out.println(gender);
}
}