-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo1.java
44 lines (37 loc) · 1.06 KB
/
demo1.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package Advances.Properties;
// https://www.youtube.com/watch?v=97Ex4VCIqBI&list=PLmOn9nNkQxJH0qBIrtV6otI0Ep4o2q67A&index=557
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
* Properties demo1
*
* <p>1) usually for config, setting - key, value are String type
*/
public class demo1 {
public static void main(String[] args) {
FileInputStream fis = null;
try {
Properties pros = new Properties();
fis = new FileInputStream("src/mySetting.properties");
pros.load(fis);
String name = pros.getProperty("name");
String pwd = pros.getProperty("pwd");
String machine = pros.getProperty("machine");
System.out.println("name = " + name);
System.out.println("pwd = " + pwd);
System.out.println("machine = " + machine);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null) {
// close resource
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}