Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why does this code behave like THIS??

Status
Not open for further replies.

sreenath205

Programmer
Dec 9, 2003
17
0
0
IN

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



if we execute this programme with command line argument it has to print the same command line argument

eg
c:\>mainerror testing
output:
c:\>mainerror testing
testing

But if we supply command line argument as * it list all files in CURRENT DIRECTORY why is it so?
Ex:
D:\2k>java test *
file_id.diz
fms.2003-04-15.full.zip
s2k.hacking.exe
s2k.info.txt
ser2k71.exe
Serials2000.nfo
serialz updates and more.url
test.class
Any answer appreciated

 
>But if we supply command line argument as * it list all files in CURRENT DIRECTORY why is it so?

* is translated by the shell interpreter before java command is called. * means all files in current directory.

Do :
c:\java mainerror &quot;*&quot;

if you want to pass character &quot;*&quot; as argument to the program.

--
Globos
 
In addition, the piece of code you wrote just prints the same thing several times, maybe you should include args instead of just args.

Cheers.

Dian
 
please use the &quot;code&quot;-tags for posting sourcecode

thx

frag

patrick.metz@epost.de
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top