简体   繁体   English

如何在命令提示符下运行使用JFileChooser类的程序?

[英]How can I run a program that uses JFileChooser class from the command prompt?

I am trying to compile a program that uses the JFileChooser class in Java from command prompt. 我正在尝试从命令提示符下编译使用Java中的JFileChooser类的程序。 My question is that if there is any type of a generic argument I can use for showOpenDialog() as a component to open a dialogue box. 我的问题是,如果有任何类型的通用参数,我可以将showOpenDialog()用作打开对话框的组件。 Here's a sample code: 这是一个示例代码:

  public class FileChooser{
      public static void main(String args[]) {
              JFileChooser chooser = new JFileChooser();
          FileReader reader= null;
          Scanner scanner= null;

          int result = chooser.showOpenDialog(null);
          if (result == JFileChooser.APPROVE_OPTION){
              File file = chooser.getSelectedFile();
              try{
              reader = new FileReader(file);
              } catch (IOException io){
                  System.out.println("File not found");
              }
              scanner = new Scanner (reader);   
              scanner.useDelimiter("\\Z");
              String s = scanner.next();
              System.out.println(s);

              }

              scanner.close();
              }
          }

I assume you are asking for showOpenDialog() argument (not JFileChooser constructor argument). 我假设您要的是showOpenDialog()参数(而不是JFileChooser构造函数参数)。 You can use null. 您可以使用null。 See JFileChooser.showDialog() for more details. 有关更多详细信息,请参见JFileChooser.showDialog() Here's the code you need 这是您需要的代码

JFileChooser chooser = new JFileChooser();
int result = chooser.showOpenDialog(null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我能够从Java程序中打开命令提示符,如何使用Java代码在此命令提示符中运行某些exe? - I was able to open a command prompt from my Java program, How to run some exe in this command prompt using java code? 如何通过控制台(命令提示符)运行 java 程序? - How do I run a java program through the console (command prompt)? 我无法通过命令提示符运行基本程序,但我可以通过 IDE 运行它 - I can't run a basic program through the command prompt, but I can run it through an IDE 如何在命令提示符下运行Java程序 - how to run a java program in command prompt 如何在命令提示符下运行Java程序 - How to run Java program in command prompt 如何将命令提示符中的变量传递到我的 java 程序中 - How can I pass variables from the command prompt into my java program 如何从 JFileChooser 中获取此值? - How can I get this value from a JFileChooser? 如何从命令提示符下运行完成的Selenium-RC项目? - How can I run a finished Selenium-RC project from command prompt? 如何从命令提示符或Eclipse在Windows(10)上的JOMP中运行多个线程? - How can I run multiple threads in JOMP on Windows (10) from either the command prompt or in Eclipse? 如何使用命令提示符在 java 中使用用户创建的包运行程序 - How do I run a program with a user created package in java using command prompt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM