aspose file tools*
The moose likes I/O and Streams and the fly likes how to get a prompt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "how to get a prompt" Watch "how to get a prompt" New topic
Author

how to get a prompt

adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi.
My requirement is to get a new window with a prompt just like this:
xyz>
and i am using BufferedReader for giving the input, and store the input in a string for further operations. But after executing the program it gives press any key to continue. I need the prompt to wait for another input from user. So how can i achive it someone knows about it please point me towards it. It would be a great help.

Thanks and Regards
alexander
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

You get a prompt by writing it to standard output (System.out). You read the input from standard in (System.in). Could you be more specific about what problem you are having?
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
yup i can say you my problem more clearly.
I use JCreator to write and execute the code. So there i get a blank window where i should enter or give the input. I think this happens even when we run the program from command prompt. So what i need is to get a prompt just like we get in windows for example take your name. Then i should get a prompt like Greg> and i f i get the output also i should get beside that prompt only but in a new line, how can i do that.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Sorry, I don't often do console I/O, and I'm not sure I really understand your question either.

Getting prompt is easy: System.out.print("Greg> ");
Reading the input is trickier. You can just read from System.in a byte at a time, but then you have to look for the line ending yourself. It's probably better to wrap System.in in a BufferedReader or something like that.
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Look at the code below you may get my problem. What you said is wright, to use System.out.print("Grg>");. Now what shall i do for output see here.




Thanks and Regards
alexander
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Yep, I think you've got it ... other than misspelling my name. You prompt for some input, read it, then echo it back to the screen. Are you saying this code doesn't work, or that you want it to do something else?
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi Greg.
Sorry for misspelling your name. My problem is there in the out put. Actually i want the prompt to wait for another input. How can i do that.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Oh, that's not hard. Just put your code into a loop. You can make it an infinite loop, or define some way to exit from it. For example, keep looping until the input is "quit". Other possibilities are "exit", "bye", "end", or "hasta la vista, baby".
adeeb alexander
Ranch Hand

Joined: May 29, 2008
Posts: 268
Hi Greg

Thanks for your help. Can you help me in this topic no one is able to understand that i think.

The topic is " how ro get a string from a string ".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get a prompt
 
Similar Threads
jsp does not display messages
Beginner in learning javascript and html problem
simple array object
More complicated Program
Sending any string via cmd. code given