/ * Xmltest.java * Created on 2004-11-16 * / package test;
import java.beans.XMLEncoder; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; public class XMLTest {public void xmlEncode () throws Exception {MyInfo my = New myinfo (); my.setMyage (25); my.setmyName ("google"); My.SetMyaddress ("China"); My.SetMyedsuCation ("Master In Science"); Xmlencoder Encoder = New Xmlencoder (New BufferedoutputStream (NEW new FileOutputStream ( "myinfo.xml"))); encoder.writeObject (my); encoder.close (); System.out.println (my);} public void xmlDecode () throws Exception {java.beans.XMLDecoder decoder = New java.beans.xmldecoder (New BufferedInputStream (New FileInputStre AM ("MyInfo.xml"))))); Myinfo my = (MyInfo) Decoder.ReadObject (); decoder.close (); system.tem.println; system.out.println ("Your Age:" My.getMYAGE (); system.out.println ("Your name:" my.getmyname ()); System.out.println ("Your Address:" my.getmyaddress ()); system.out.println ("Your Education:" my.getMyed Technology ();} public static void main (string args []) throws exception {xmltest st = new xmltest (); st.xmlDecode (); st.xmldecode ();
}} The corresponding secondary MYINFO code is as follows: package test; / ** * Add one senence class summary here. * Add class description here. * * @Author lxx * @version 1.0, 2004-11-16 * /
public class MyInfo {private int myAge; private String myName; private String myAddress; private String myEducation; public MyInfo () {} public int getMyAge () {return myAge;} public void setMyAge (int age) {this.myAge = age; } public String getMyName () {return myName;} public void setMyName (String name) {this.myName = name;} public String getMyAddress () {return myAddress;} public void setMyAddress (String address) {this.myAddress = address; } Public string getMyeducation () {return myeducation;} public void setMyeducation (String education) {this.myeducation =
}