/* * BinaryFileMaker.java * * This program demonstrates creation of a sequential binary file.  The * user is prompted via a file dialog to specify the name of a file to be * created, and then is prompted via a dialog box to specify a boolean, * char, byte, short, int, long, float, double, and String to be written * to the file.  Each value is written to the file.  (In the case of the * String, its length is first written as an int. * * The resultant file can be read back using BinaryFileAccessor.java * * Copyright (c) 2000, 2004 - Russell C. Bjork * */import java.io.*;import javax.swing.*;public class BinaryFileMaker{    public static void main(String [] args) throws IOException    {        // Create the file        		File filename;		JFileChooser chooser = new JFileChooser(System.getProperty("user.dir"));		if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION)		{			filename = chooser.getSelectedFile();		}		else			return;			        DataOutputStream output = new DataOutputStream(        	new FileOutputStream(filename));                // Get the values to write from the user and convert to appropriate        // types        		String [] inputLabels = { "Boolean", "Char", "Byte", "Short", 								  "Int", "Long", "Float", "Double", "String" };				String [] valuesToWrite = MultiInputPane.showMultiInputDialog(			null, inputLabels, "Values to write");                        boolean booleanValue = (new Boolean(valuesToWrite[0])).booleanValue();        char charValue = valuesToWrite[1].charAt(0);        byte byteValue = (new Byte(valuesToWrite[2])).byteValue();        short shortValue = (new Short(valuesToWrite[3])).shortValue();        int intValue = (new Integer(valuesToWrite[4])).intValue();        long longValue = (new Long(valuesToWrite[5])).longValue();        float floatValue = (new Float(valuesToWrite[6])).floatValue();        double doubleValue = (new Double(valuesToWrite[7])).doubleValue();        String stringValue = valuesToWrite[8];                // Write the values to the file                output.writeBoolean(booleanValue);        output.writeChar(charValue);        output.writeByte(byteValue);        output.writeShort(shortValue);        output.writeInt(intValue);        output.writeLong(longValue);        output.writeFloat(floatValue);        output.writeDouble(doubleValue);        output.writeInt(stringValue.length());        output.writeChars(stringValue);                // Close the file and we're done                output.close();        System.exit(0);    }}        