Object serialization in groovy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // put this in a file named Name.groovy and compile using groovyc class Name implements Serializable { def fname, lname } // Now run the code below to see the Object serialization and de-serialization. def test1= new Name(fname: "fn1", lname : "ln1") def test2 = new Name(fname: "fn2", lname: "ln2") //serialization new File("C:/config.txt").withObjectOutputStream { out -> out << test1 out << test2 } //de-serialization new File("C:/config.txt").withObjectInputStream { instream -> instream.eachObject { println it } } |
Source: satish.name