-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPropertiesTest.java
More file actions
36 lines (30 loc) · 1021 Bytes
/
Copy pathPropertiesTest.java
File metadata and controls
36 lines (30 loc) · 1021 Bytes
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
package java_base;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
public class PropertiesTest {
public static void main(String[] args) throws Exception{
Properties props = new Properties();
props.setProperty("dept", "计算机学院");
props.setProperty("username", "hdczyj");
props.setProperty("password", "123456");
FileOutputStream fos = new FileOutputStream("a.ini");
props.store(fos, "注释行");
System.out.println(props);
fos.close();
Properties props2 = new Properties();
props2.setProperty("gender", "male");
props2.setProperty("dept", "Handan College");
FileInputStream fis = new FileInputStream("a.ini");
props2.load(fis);
System.out.println(props.get("dept"));
FileOutputStream fos1 = new FileOutputStream("a.ini");
// System.out.println("\u6559\u52A1\u5904");
// System.out.println("\u6559\u52A1\u5904");
props2.store(fos1, "\u6559\u52A1\u5904");
System.out.println(props2);
}
}
/*
* key 是唯一的,value 会被取代
*/