Java tutorial
//package com.java2s; import java.awt.FileDialog; import javax.swing.JFrame; public class Main { /** * @param jFrame * @param currentDirectory * @return You can get the filename with fileDialog.getFile(), * and you can get the directory with fileDialog.getDirectory(). * String filename = fileDialog.getDirectory() + System.getProperty("file.separator") + fileDialog.getFile(); * */ public static FileDialog letUserChooseFile(JFrame jFrame, String currentDirectory) { FileDialog fileDialog = new FileDialog(jFrame); fileDialog.setModal(true); fileDialog.setMode(FileDialog.LOAD); fileDialog.setTitle("Open a File"); if (currentDirectory != null && !currentDirectory.trim().equals("")) { fileDialog.setDirectory(currentDirectory); } fileDialog.setVisible(true); return fileDialog; } }