Android JFileChooser Show selectFileForRead(Component parent)

Here you can find the source of selectFileForRead(Component parent)


Select a file for read opt.


public static File selectFileForRead(Component parent) 

Method Source Code

//package com.java2s;
import java.awt.Component;


import javax.swing.JFileChooser;

public class Main {

    public static File selectFileForRead(Component parent) {
        // Create a file chooser
        final JFileChooser fc = new JFileChooser("");


        // In response to a button click:
        int returnVal = fc.showOpenDialog(parent);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            return fc.getSelectedFile();
        }//from w  ww . j a va  2 s  .  c o m

        if (returnVal == JFileChooser.CANCEL_OPTION) {
            return null;

        throw new RuntimeException("file exception when select file.");