Jump to content

Need Explanation please

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
ld_pvl

ld_pvl

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
This is a sample that my instructor gave me for a simple program to create a copy of an existing file and then put all the characters to lower case.

There's a thing which I'm not quite sure about and really want to make it clear.

When we write
 public static void main(String[] args) 
, does that mean we allowed to put a vector of parameters when we run the program?

Like in this case when running the program we should enter: java Lowercase text1.txt text2.txt

Basically, if anyone can explain to be the "args" parts, I would be very grateful for that.

Thanks


import java.io.*;


public class Lowercase {

	public static void main(String [] args) {

		try {

			FileInputStream fileIn = new FileInputStream(args[0]);

			FileOutputStream fileOut = new FileOutputStream(args[1]);

			int i;


			while ((i = fileIn.read()) != -1) {

				fileOut.write(Character.toLowerCase((char)i));

			}

		} catch (IOException e) {

			 System.err.println(e);

		}

	}

}



#2
mike85tyler

mike85tyler

    Newbie

  • Members
  • Pip
  • 2 posts
When you look at the main method, you see that it is being passed an array of Strings that it calls args. So when you use that java command text1 and text2 are being stored in a String array called args.

#3
ld_pvl

ld_pvl

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
thanks