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

Reading a String

Othmar Stehlik
Ranch Hand

Joined: Jul 24, 2001
Posts: 36
Hi
Can someone please give me an explicit example, hiw to read a String from the command ine?
I�m still confused with the different type of Inputstreams, and how to apply them.
Thanx
Othmar
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Othmar
When your main method executes it is sent all of the command line arguments (arguments after the class name) as an array of strings referenced by the args variable. Then you can access them by just refering to the position in the array of the argument you want. For example, say you have a class called Test, that looks like this:

If you run it with a command line entry like this:
java Test 1 26 Fred
Then your output would be:

Hope that helps

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
You don't need InputStreams to read from the command line. Here is a link with more information on getting arguments from the command line.


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

Joined: Oct 08, 2001
Posts: 3
Whenever you enter any value through command line. its in a form of string and Storing (String[]args) -----> there...
so, if you want to print these words...just write..
System.out.println("The Values are "+args[0]);
If you enter more then one values just put a loop in your code, like
for (int i=o;i<args.lenght;i++) {>
System.out.println("The Values are "+ " " + args[i]);
}
Bye Happy Coding...
Khurram
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Here is a sample of requesting input during an application - without a gui.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Othmar Stehlik
Ranch Hand

Joined: Jul 24, 2001
Posts: 36
Hi
Thanx to all who posted this usefull links and examples!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading a String