2

I am trying to prompt "open file window" from command prompt in java and planning to take that selected file as input file instead of

FileInputStream fis=new FileInputStream(args[0]);

but not succeeded yet, please some tell me how to do it in command prompt in java.

G33K_C0D3R
  • 67
  • 1
  • 9
  • Maybe it's solution you need : http://stackoverflow.com/questions/4688123/how-to-open-the-command-prompt-and-insert-commands-using-java – Tea Dec 01 '16 at 15:43
  • 1
    You're looking for the JFileChooser class. FileInputStream is an inputstream, not a popup window. – OneCricketeer Dec 01 '16 at 15:46

1 Answers1

7

You can use a JFileChooser to be able to select a file from a dialog box.

Assuming you want to launch it outside a Java Swing application, you could proceed as next:

final JFileChooser fc = new JFileChooser();
// Open the dialog using null as parent component if you are outside a
// Java Swing application otherwise provide the parent component instead
int returnVal = fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    // Retrieve the selected file
    File file = fc.getSelectedFile();
    try (FileInputStream fis = new FileInputStream(file)) {
        // Do something here
    }
}

More details about How to Use File Choosers

Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122