将参数传递给java [英] passing argument to java

查看:87
本文介绍了将参数传递给java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是java新手请帮帮我



如何在java中传递参数作为文本文件和整数。



例如java routing.java inputfile 2

Hi
I am very new to java please help me

how to pass arguments as text file and integer number in java.

e.g java routing.java inputfile 2

推荐答案

或多或少如上所示,除了您不要尝试运行 .java 文件。首先需要使用 javac 命令编译Java源代码,然后运行类文件:

More or less as you have shown above, except that you do not try to run the .java file. You first need to compile your Java source with the javac command, and then run the class file thus:
javac routing.java
java routing inputfile 2



然后从<$ c $的 args 参数访问输入参数c> main()方法。以下代码演示了基本功能:


The input parameters are then accessed from the args argument of the main() method. The following code demonstrates the basic functionality:

public static void main(String[] args) {
    if (args.length > 0) {
        System.out.println("Application arguments:");
        for (String argName : args) {
            System.out.format("\t%s%n", argName);
        }
        System.out.println("");
    }
}


这篇关于将参数传递给java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆