Here you can find the source of getOpenFile(String name, String currentDirectory)
public static File getOpenFile(String name, String currentDirectory)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.io.*; public class Main { protected static String gLastDirectory = System.getProperty("user.dir"); public static File getOpenFile(String name, String currentDirectory) { return getOpenFile(name, currentDirectory, null); }// w ww. ja v a2 s . co m public static File getOpenFile(String name, String currentDirectory, String[] extension) { if (currentDirectory == null) currentDirectory = gLastDirectory; JFileChooser fc = new JFileChooser(currentDirectory); File directory = new File(currentDirectory); File theFile = new File(directory, name); fc.setCurrentDirectory(directory); fc.setSelectedFile(theFile); fc.setDialogType(JFileChooser.OPEN_DIALOG); int ret = fc.showSaveDialog(null); if (ret == JFileChooser.APPROVE_OPTION) { File selectedFile = fc.getSelectedFile(); gLastDirectory = selectedFile.getParent(); return selectedFile; } else { return null; } } }