【问题标题】:how to prompt "open file window" from command prompt in java? [duplicate]如何在java中从命令提示符提示“打开文件窗口”? [复制]
【发布时间】:2016-12-01 15:40:59
【问题描述】:

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

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

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

【问题讨论】:

标签: java file command-prompt openfiledialog


【解决方案1】:

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

假设您想在 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的详情

【讨论】:

  • thanx 兄弟,你是救命稻草,尤其是thanx 回复这么快
猜你喜欢
  • 2019-08-11
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
  • 2012-12-02
相关资源
最近更新 更多