Topic: 求助如何接收java 命令传入的参数???

  Print this page

1.求助如何接收java 命令传入的参数??? Copy to clipboard
Posted by: 寂寞高手
Posted on: 2005-04-07 12:32

我有一个程序,想在MAIN()方法中接收从JAVA命令中键入的参数,不如何的用args[]数组进行接收,请大家帮我一下.谢谢.

2.Re:求助如何接收java 命令传入的参数??? [Re: 寂寞高手] Copy to clipboard
Posted by: Sunteya
Posted on: 2005-04-07 13:33

你先建个叫ArgsTest.java的文件然后输入:
/*
* Create on 2005-4-7
* Create by Sunteya
*/

public class ArgsTest {
  public static void main(String[] args) {
    for (int i = 0; i < args.length; i++) {
      System.out.println("args[" + i + "] : " + args[i]);
    }
  }
}


接着编译(javac),然后再控制台里输入
java ArgsTest text1 text2       text3 "t e x t 4" *.classs

自己看看输入和args的关系吧。

3.Re:求助如何接收java 命令传入的参数??? [Re: 寂寞高手] Copy to clipboard
Posted by: zaowei21
Posted on: 2005-04-07 14:41

加空格就可以了。

4.Re:求助如何接收java 命令传入的参数??? [Re: 寂寞高手] Copy to clipboard
Posted by: ginger547
Posted on: 2005-04-08 14:58

java yourProgram args0 args1.....


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923