Java JFileChooser chooseFile()

Here you can find the source of chooseFile()

Description

Chooses the file which is examined via a simple folder browser Dialog

License

Open Source License

Parameter

Parameter Description
Does not need any to begin with.

Return

: string for file path

Declaration


public static String chooseFile() throws FileNotFoundException 

Method Source Code

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

import java.io.FileNotFoundException;

import javax.swing.JFileChooser;

public class Main {
    /**//  www . j  a  v  a  2  s . com
     * Chooses the file which is examined via a simple folder browser Dialog
     * 
     * @param Does
     *            not need any to begin with.
     * @return: string for file path
     */

    public static String chooseFile() throws FileNotFoundException {
        JFileChooser j = new JFileChooser();
        j.setFileSelectionMode(JFileChooser.FILES_ONLY);
        j.showOpenDialog(j);
        if (j.getSelectedFile() == null) {
            System.out.println("No file was chosen");
        } else {
            String file = j.getSelectedFile().getPath();
            return file;
        }
        return null;

    }
}

Related

  1. askUserForFileURL(Component aParent, boolean bOpen)
  2. browseFileForList(DefaultListModel listModel, JFileChooser fileChooser, Component parent)
  3. chooseDirectory(Component parentComponent, File directory, String title)
  4. chooseDirectory(String name, final String desc, File curdir)
  5. chooseFile()
  6. chooseFile(Component p, String message, boolean toOpen, int fileType)
  7. chooseFile(Component parent, String title, boolean open)
  8. chooseFile(Component parentComponent, String title, File curDir, String suffix)
  9. chooseFile(File initialFile, boolean load)