luinzi
asked on
Interactive prompts from command line?
Hi there,
I have written a program that runs on a Unix commandline. Sadly I have to parse it over 15 arguments when I run it. Is there anyway that I can in my main method get the program to run and then print line a prompt statement telling a user which parameter to enter so that I can then pump this into a variable for use? ie on the command line I want to see the following:
>java comparator --run the program
>Please enter Value 1: 3 --user enters this value
>Please enter output dir: c:\oput\ --user enters this
>Please.... etc etc
I assume I will need some kind of While statement?
Does anyone have a clue what i'm on about? Can anyone help?
Many Thanks...............
I have written a program that runs on a Unix commandline. Sadly I have to parse it over 15 arguments when I run it. Is there anyway that I can in my main method get the program to run and then print line a prompt statement telling a user which parameter to enter so that I can then pump this into a variable for use? ie on the command line I want to see the following:
>java comparator --run the program
>Please enter Value 1: 3 --user enters this value
>Please enter output dir: c:\oput\ --user enters this
>Please.... etc etc
I assume I will need some kind of While statement?
Does anyone have a clue what i'm on about? Can anyone help?
Many Thanks...............
ASKER
Thats great but I want to enter strings.
This is what I have done so far:
InputStream f;
String a;
while ((a = f.read()) != null)
{
System.out.println("Enter Value: ");
}
System.out.println("Value entered was: "+ a);
It thinks I'm trying to enter an integer?
C:\jdk1.3\bin\comparator.j ava:155: incompatible types
found : int
required: java.lang.String
while ((a = f.read()) != null)
^
1 error
I don't even know if this is the right way of going about it? How would I use the System.in.read?
This is what I have done so far:
InputStream f;
String a;
while ((a = f.read()) != null)
{
System.out.println("Enter Value: ");
}
System.out.println("Value entered was: "+ a);
It thinks I'm trying to enter an integer?
C:\jdk1.3\bin\comparator.j
found : int
required: java.lang.String
while ((a = f.read()) != null)
^
1 error
I don't even know if this is the right way of going about it? How would I use the System.in.read?
for reading you can use
BufferedReader reader = new BufferedReader(new InputStreamReader(System.i n));
String st = reader.readLine();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.i
String st = reader.readLine();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got it working! Thanks..................
so why did you give me grade B ?
System.out.print("Please enter Value 1:");
System.in.read(...);