Java Swing Tutorial - Java JFileChooser .getSelectedFiles ()








Syntax

JFileChooser.getSelectedFiles() has the following syntax.

public File [] getSelectedFiles()

Example

In the following code shows how to use JFileChooser.getSelectedFiles() method.

//  w  w  w.  jav a  2s.co m

import java.io.File;

import javax.swing.JFileChooser;

public class Main {

  public static void main(String[] a) {
    JFileChooser fileChooser = new JFileChooser(".");
    int status = fileChooser.showOpenDialog(null);

    if (status == JFileChooser.APPROVE_OPTION) {
      File[] selectedFiles = fileChooser.getSelectedFiles();
    } else if (status == JFileChooser.CANCEL_OPTION) {
      System.out.println("canceled");
    }
  }

}