How to serialize with java
This article mainly introduces how to use java to achieve serialization, the article is very detailed, has a certain reference value, interested friends must read it!
Package test
Import java.io.*
Public class Test implements Serializable {
Int iTunes 0
/ / do not let variable j serialize
Transient int jung0
Public static void main (String [] args) {
Test test=new Test ()
Test.i=3
Test.j=7
System.out.println (test.i)
System.out.println (test.j)
/ / save
FileOutputStream fileStream = null
Try {
FileStream = new FileOutputStream ("c: est.obj")
ObjectOutputStream out = new ObjectOutputStream (fileStream)
Out.writeObject (test)
Out.close ()
}
Catch (Exception ex) {
}
Try {
/ / fetch
FileInputStream fileStream1 = new FileInputStream ("c:product.obj")
ObjectInputStream in = new ObjectInputStream (fileStream1)
Test test1 = (Test) in.readObject ()
System.out.println (test1.i)
/ / j is not serialized
System.out.println (test1.j)
In.close ()
}
Catch (Exception ex) {
}
}
}
The above is all the contents of the article "how to serialize with java". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!