Java JFileChooser openFile()

Here you can find the source of openFile()

Description

open File

License

Open Source License

Declaration

public static String openFile() 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

import javax.swing.JFileChooser;

public class Main {
    public static String openFile() {
        JFileChooser fc = null;/*from  w  w  w.  j  a va  2s . c  o  m*/

        fc = new JFileChooser(System.getProperty("user.home"));
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        int returnVal = fc.showOpenDialog(null);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            if (file.getPath().equals(""))
                return null;
            return file.getAbsolutePath();
        }
        return null;
    }
}

Related

  1. loadFile()
  2. loadFile(Component parent, String title)
  3. loadFileAs(Class clazz, String json)
  4. makeFileChooser()
  5. openDataFileChooser(Component com)
  6. openFile(String fileExtension)
  7. promptFile(File file, FileFilter filter, String title)
  8. promptForFilename(String title)
  9. PromptForFileOpen(Component c)