Here you can find the source of chooseFile(File initialFile, boolean load)
public static File chooseFile(File initialFile, boolean load)
//package com.java2s; //License from project: Open Source License import javax.swing.*; import java.io.*; import java.awt.FileDialog; public class Main { public static File chooseFile(File initialFile, boolean load) { if (isMac()) { FileDialog d = new FileDialog((java.awt.Frame) null); d.setMode(load ? FileDialog.LOAD : FileDialog.SAVE); if (initialFile != null) { d.setDirectory(initialFile.getParent()); d.setFile(initialFile.getName()); }/*from w w w . j a va 2s. c o m*/ d.show(); String f = d.getFile(); if (f != null) return new File(new File(d.getDirectory()), d.getFile()); } else { JFileChooser chooser = new JFileChooser(); if (initialFile != null) chooser.setSelectedFile(initialFile); if ((load ? chooser.showOpenDialog(null) : chooser.showSaveDialog(null)) == JFileChooser.APPROVE_OPTION) return chooser.getSelectedFile(); } return null; } public static boolean isMac() { return System.getProperty("os.name").startsWith("Mac"); } }