如何从java中的命令提示符提示“打开文件窗口”? [重复]

时间:2022-09-28 09:47:28

This question already has an answer here:

这个问题在这里已有答案:

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

我试图从java中的命令提示符提示“打开文件窗口”,并计划将所选文件作为输入文件而不是

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

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

但是还没有成功,请告诉我如何在java中的命令提示符下执行此操作。

1 个解决方案

#1


2  

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

您可以使用JFileChooser从对话框中选择文件。

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

假设您想在Java Swing应用程序之外启动它,您可以继续下一步:

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 comment 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

有关如何使用文件选择器的更多详细信息

#1


2  

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

您可以使用JFileChooser从对话框中选择文件。

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

假设您想在Java Swing应用程序之外启动它,您可以继续下一步:

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 comment 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

有关如何使用文件选择器的更多详细信息