aspose file tools*
The moose likes Beginning Java and the fly likes A simple program ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A simple program ???" Watch "A simple program ???" New topic
Author

A simple program ???

Vaskar Dasgupta
Greenhorn

Joined: Jul 20, 2001
Posts: 25
class test{
public static void main(String args[]){
for (int i = 0;i < args.length; i++) {
System.out.println("File " + i + ":" + args[i]);
}
if (args.length<=0) {
System.out.println("No files!");
}
}
}
Compile it and
Run this program using - java test * (its a star)
The out put of this program is the name of the files and folders in the directory from where it is run. No other special character used in the command prompt works like this except *......Any explanations ???
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
the '?' also works

[ February 06, 2002: Message edited by: Marilyn deQueiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Vaskar Dasgupta
Greenhorn

Joined: Jul 20, 2001
Posts: 25
java ?.java ...................... i didn't get it, does not work for me. ? is not the name of the file so ?.java will throw a exception " Exception in thread "main" java.lang.NoClassDefFoundError: ?/java "
Erik Dark
Ranch Hand

Joined: Jan 28, 2002
Posts: 107
Doesn't work for me neither. Suppose Marilyn meant
But that also doesn't work...Marilyn can you explain what you mean? (learned you can browse your current directory this way..did'nt know!)
TIA Erik Dark
[ February 06, 2002: Message edited by: Erik Dark ]
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Vaskar,
In java you always need to include the name of the program. How else would the JVM know which class to execute?
Marilyn just made a small typo:
input:
java TestListFiles ?.java
Regards,
Manfred.
Vaskar Dasgupta
Greenhorn

Joined: Jul 20, 2001
Posts: 25
I am sorry to say even that doesnt work for me... i mean the ?......... "java fileName ?.java" does not work for me at all....this is my output, my file name is test.java
D:\>java test ?.java
?.java
Vaskar Dasgupta
Greenhorn

Joined: Jul 20, 2001
Posts: 25
can you give an explanation for my first query java test * (the star) ???
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
All they are showing is that using the * as an input parameter points back to the contents of the directory that you are sitting in at execution time.
So when you say
>java Test *
you are saying "execute Test with this directories content list as input".
Try
>java Test *.java
and you will get a list of just those files that end with .java.
Vaskar Dasgupta
Greenhorn

Joined: Jul 20, 2001
Posts: 25
How does the JVM understand that, when it is DOS command. Is it something to do with the way the program 'java.exe' works ? Awaiting a reply..............
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
(Of course it was a typo - I've edited my previous post)

Since the JVM is written in native code, it would seem logical that it could use a wild card in DOS. It would also seem logical that the same would hold true in a JVM in a unix/linux environment. I wonder if this would also happen in a MacIntosh JVM.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The JVM never sees the '*' - it is interpreted by the operating system before it is passed to the JVM.


"I'm not back." - Bill Harding, Twister
Vaskar Dasgupta
Greenhorn

Joined: Jul 20, 2001
Posts: 25
As far as i understand java.exe by default will look for the class files in the current directory where it is being run from, using a * buffers the directory contents, and the small simple program parsers the * to get the output on the screen..............Somebody please give adetailed explanation, if possible how the code actually works if by using a verbose output (java -verbose test * .........Could not get anything after trying for myself). Any figures or aatachments are welocome to
d_vaskar.cgmaersk@maerskdata.dk
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A simple program ???