从XML反序列化Bean
import java.beans.XMLDecoder; /** from 时 代 J a v a 公 众 号 - nowjava.com**/ import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; public class Main { public static void main(String[] args) throws Exception { try { XMLDecoder decoder = new XMLDecoder(new BufferedInputStream( new FileInputStream("infilename.xml"))); MyClass o = (MyClass) decoder.readObject(); decoder.close(); // Use the object int prop = o.getProp(); // 1/*时代Java*/ int[] props = o.getProps(); // [1, 2, 3] } catch (FileNotFoundException e) { } } } class MyClass{ int prop; int[] props; public int getProp() { return prop; } public void setProp(int prop) { this.prop = prop; }