Java JFileChooser openFile(String fileExtension)

Here you can find the source of openFile(String fileExtension)

Description

open File

License

Open Source License

Declaration

public static String openFile(String fileExtension) 

Method Source Code

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

import java.io.*;

import javax.swing.JFileChooser;

public class Main {
    public static String openFile(String fileExtension) {
        JFileChooser dlgFile = new JFileChooser();
        dlgFile.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        dlgFile.setApproveButtonText("Open");

        int returnVal = dlgFile.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = dlgFile.getSelectedFile();
            return file.getAbsolutePath();
        }//from  ww  w.  j ava2s  .c o m
        return "";
    }
}

Related

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