Properties:
A subclass of Hashtable, which belongs to the collection class. Store property The key value pair of the heart, the key and the value by default is a string is a collection class that can be used in conjunction with a stream
Properties Pro = new properties ();
Pro.setproperty ("name", "Tom");
Pro.setproperty ("Age", "19");
Pro.setproperty ("Sex", "boy");
System.out.println (PRO);
// 获得所有属性名的集合 Set<String> names = pro.stringPropertyNames(); Iterator<String> it = names.iterator(); while (it.hasNext()) { String key = it.next(); String value = pro.getProperty(key); System.out.println(key + "----" + value); }
Used in conjunction with file streams:
Load the. properties file through the Properties class and read the information
1 Stream 2 Create a Properties object, load a property file 3 read the information by means of the attributes object
Write Properties File
static void WriteProperties (file file, Map
Data flow: specifically used to write basic types of data, read and write the order of strict correspondence
DataInputStream (InputStream)
ReadInt ()
Readdouble ()
readUTF ()
DataOutputStream (OutputStream)
Writeint ()
Writedouble ()
writeUTF ()
Flush ()
Create a data flow
DataOutputStream OS = new DataOutputStream (New FileOutputStream (
"Src/data.txt"));
Os.writedouble (12.2);
Os.writeint (10);
Os.writeutf ("Study hard");
Os.flush ();
// 读 DataInputStream is = new DataInputStream(new FileInputStream( "src/data.txt")); System.out.println(is.readDouble()); System.out.println(is.readInt()); System.out.println(is.readUTF());
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Basic notes (vii)