import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;

public class DirChooser {
	public static void main (String[] args) {
		File choice = null;
		JFileChooser fc = new JFileChooser ();

		if (args.length >= 1) {
			fc.setDialogTitle(args[0]);
		} else {
			fc.setDialogTitle("Set directory");
		}

		fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		fc.setMultiSelectionEnabled(false);

		if (args.length >= 2) {
			fc.showDialog(null, args[1]);
		} else {
			fc.showOpenDialog(null);
		}

		choice = fc.getSelectedFile();

		try {
			if (choice != null) {
				System.out.println(choice.getCanonicalPath());
			}
			System.exit(1);
		} catch (IOException ioe) {
			ioe.printStackTrace(System.err);
		}
	}
}
