Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 参数args.length是什么意思?_Java_Args - Fatal编程技术网

Java 参数args.length是什么意思?

Java 参数args.length是什么意思?,java,args,Java,Args,我想请您帮助解释args.length=2在下面的程序中。在书中我读到他们检查是否有两个文件,但为什么使用!感叹号?这对我来说没有意义。我找到了关于args.length的信息,但没有找到关于这个检查文件的信息,甚至在stackowerflow上也没有,因此我在这里询问。多谢各位 java CopyFile first.txt second.txt - this is put on comand line import java.io.*; class CopyFile{ public

我想请您帮助解释args.length=2在下面的程序中。在书中我读到他们检查是否有两个文件,但为什么使用!感叹号?这对我来说没有意义。我找到了关于args.length的信息,但没有找到关于这个检查文件的信息,甚至在stackowerflow上也没有,因此我在这里询问。多谢各位

java CopyFile first.txt second.txt - this is put on comand line

import java.io.*;

class CopyFile{
  public static void main(String args[]) throws IOException{

    int i;

      FileInputStream fileIn = null;
      FileOutputStream fileOut = null;

        **//firstly check whether both two files has been set up**
        if(args.length != 2) {
          System.out.println("Using: CopyFile system");
          return;
        }

Java不会将Java类文件名放在args[]中,args[]只包含作为主函数参数传递的参数,因此在您的示例中,此条件args.length!=2检查在执行命令时是否向主函数传递了两个参数:

javac classFile.java=>编译java文件。 java classFile one two=>使用“one”和“two”作为参数执行主函数。
!= 在Java和其他几种语言中表示不等于。我建议大家阅读基本的语言语法,例如各种运算符,请参见。逻辑是在命令行上查找两个参数。如果没有两个参数,程序会打印出这条小消息并返回Hanks nicomp现在我明白了。嗨,Brahim Khouy,谢谢你的解释。现在清楚了。