import java.io.*; /** * WriteQuark serializes an instance of Quark. */ public class WriteQuark { public static void main(String[] args) { // Check command-line args. if (args.length < 3) { System.out.println("Usage: WriteQuark file flavor charge"); 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 object output stream. ObjectOutputStream ostream = new ObjectOutputStream(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); } } }