Here you can find the source of getOpenFile(String defaultPath)
Parameter | Description |
---|---|
defaultPath | a parameter |
public static File getOpenFile(String defaultPath)
//package com.java2s; //License from project: Open Source License import java.io.File; import javax.swing.JFileChooser; public class Main { /**// w w w . ja v a2s. c o m * Generic method to get a file using a JFileChooser * * @param defaultPath * @return the File or null if aborted. */ public static File getOpenFile(String defaultPath) { File file = null; JFileChooser chooser = new JFileChooser(); if (defaultPath != null) { chooser.setCurrentDirectory(new File(defaultPath)); } int result = chooser.showOpenDialog(null); if (result == JFileChooser.APPROVE_OPTION) { // Save the selected path for next time defaultPath = chooser.getSelectedFile().getParentFile().getPath(); // Process the file file = chooser.getSelectedFile(); } return file; } }