A, Properties *** properties depend on the class file (key-value pair container).
Constructor: Properties ();
common methods: Properties Object .put (key, value) // set values
Properties object .getProperty (String key); // get the value
Properties object .load (InputStream is); // file to the loading *** properties Properties object.
Properties object .store (OutputStream out, String str (second parameter values comment)); // Properties object to be output to ***. properties file
Second, the serialization and deserialization stream flow
1, the sequence of flow (ObjectOutputStream):
Constructor: ObjectOutputStream (FileOutputStream fos)
commonly used methods: writeObject (Object obj);
2, the sequence of return flow (ObjectIntputStream):
Constructor: ObjectIntputStream (FileIntputStream fis)
commonly used methods: reafObject ()
It needs to be serialized and deserialized columns must implement the Serializable interface need not be a sequence of fields may be transient modified example ( Private transient int Age;)
1 public class Person implements Serializable { 2 private String name; 3 private int age; 4 public String getName() { 5 return name; 6 } 7 public void setName(String name) { 8 this.name = name; 9 } 10 public int getAge() { 11 return age; 12 } 13 public void setAge(int age) { 14 this.age = age; 15 } 16 @Override 17 public String toString() { 18 return "Person [name=" + name + ", age=" + age + "]"; 19 } 20 public Person(String name, int age) { 21 super(); 22 this.name = name; 23 this.age = age; 24 } 25 26 public Person() { 27 super(); 28 } 29 30 }
1 // serialization 2 Private void Write () throws IOException { . 3 the Person P = new new the Person ( "Little Red Riding Hood", 18 ); 4 // clear the data source . 5 a FileOutputStream fos = new new a FileOutputStream ( "D: \\ \\ demo0723 the Person .txt " ); . 6 // create a serialized stream . 7 the ObjectOutputStream OOS = new new the ObjectOutputStream (fos); . 8 . 9 // write 10 oos.writeObject (P); . 11 oos.close (); 12 is } 13 is 14 @ deserialization 15 public static void Read () throws IOException, a ClassNotFoundException { 16 // clear the data source . 17 the FileInputStream FIS = new new the FileInputStream ( "D: \\ \\ Person.txt demo0723" ); 18 is // Create serialization stream back . 19 the ObjectInputStream OIS = new new the ObjectInputStream (FIS); 20 is // read from the person.txt 21 is // Boolean data type B = instanceof Object; 22 // Person P = (Person)ois.readObject(); 23 24 boolean b = ois.readObject() instanceof Person; 25 System.out.println(b); 26 27 // System.out.println(p); 28 ois.close(); 29 }