【问题标题】:Command line argument javafx命令行参数 javafx
【发布时间】:2019-03-07 08:10:34
【问题描述】:

我正在尝试编写一个简单的程序来使用 javafx 绘制折线图。

我有以下代码:

public class Plot extends Application {
  public void start(Stage stage){

  }

  public static void main(String[] args) {
    launch(args);
  }
}

我希望能够在运行程序时将 .csv 文件作为命令行参数传递。并从内部访问文件:

 public void start(Stage stage){
 }

【问题讨论】:

    标签: java javafx command-line-arguments


    【解决方案1】:

    您可以使用 Application 类 (docs) 中的 getParameters() 方法。

    public class MyApp extends Application {
        @Override
        public void start(Stage primaryStage) {
            // for example list all given parameters
            getParameters().getRaw().forEach(System.out::println);
            // ...
        }
    
        public static void main(String[] args) {
            launch(args);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-02
      • 2016-03-25
      • 1970-01-01
      • 2011-02-25
      • 2013-02-14
      相关资源
      最近更新 更多