/* * RandomFileAccessor.java * * This program reads back a value from a user-specified position in the file * created by BinaryFileMaker.java, and displays it as all possible data types. * See that program for a description of the file * * Copyright (c) 2000, 2004 - Russell C. Bjork * */import java.io.*;import javax.swing.*;public class RandomFileAccessor{    public static void main(String [] args) throws IOException    {        // Open the file        		File filename;		JFileChooser chooser = new JFileChooser(System.getProperty("user.dir"));		if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)		{			filename = chooser.getSelectedFile();		}		else			return;			        RandomAccessFile input = new RandomAccessFile(filename, "r");        		do		{			// Get the position in the file					String positionString = JOptionPane.showInputDialog(				"Position (cancel to quit): ");			if (positionString == null)				break;	// Exit loop when null is entered			long position = Long.parseLong(positionString);				        // Read the values from the file        			input.seek(position);			boolean booleanValue = input.readBoolean();			input.seek(position);			char charValue = input.readChar();			input.seek(position);			byte byteValue = input.readByte();			input.seek(position);			short shortValue = input.readShort();			input.seek(position);			int intValue = input.readInt();			input.seek(position);			long longValue = input.readLong();			input.seek(position);			float floatValue = input.readFloat();			input.seek(position);			double doubleValue = input.readDouble();			// Don't try the string								// Write out what we read						System.out.println();			System.out.println("Values read as various types at position " +				position);			System.out.println("boolean: " + booleanValue);			System.out.println("char:    " + charValue);			System.out.println("byte:    " + byteValue);			System.out.println("short:   " + shortValue);			System.out.println("int:     " + intValue);			System.out.println("long:    " + longValue);			System.out.println("float:   " + floatValue);			System.out.println("double:  " + doubleValue);			System.out.println();		}		while(true);	// Loop is mid-exit		        // Close the file and we're done                input.close();        System.exit(0);             }}