import java.beans.*; import java.io.*; /** * WriteQuarkXML serializes an instance of Quark as XML. */ public class WriteQuarkXML { public static void main(String[] args) { // Check command-line args. if (args.length < 1) { System.out.println("Usage: WriteQuarkXML file"); System.exit(0); } try { // Get command-line args. String file = args[0]; String flavor = args[1]; int charge = Integer.parseInt(args[2]); // Create a Quark. Quark q = new Quark(); q.setFlavor(flavor); q.setCharge(charge); // Create file output stream. FileOutputStream fstream = new FileOutputStream(file); try { // Create XML encoder. XMLEncoder ostream = new XMLEncoder(fstream); try { // Write object. ostream.writeObject(q); ostream.flush(); } finally { // Close object stream. ostream.close(); } } finally { // Close file stream. fstream.close(); } } catch(Exception ex) { System.out.println(ex); } } }