如何在 java 中从命令提示符提示 "open file window"?

how to prompt "open file window" from command prompt in java?

我正尝试在 java 中从命令提示符提示 "open file window" 并计划将所选文件作为输入文件而不是

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

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

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

假设您想在 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 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
    }
}

有关 How to Use File Choosers

的更多详细信息