Results 1 to 5 of 5
- 12-25-2010, 09:06 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
Input a line from System.in without doing a CR/LF
Hi Guys,
Just joined up. Hello everyone.
I'm using Java for the first time, and I've been trying to figure this one out for hours and it's bugging me. Can anyone help?
I want to get some input from System.in, but when I press 'Enter' I don't want to do a CR/LF - I want the response from my program to be printed on the same line that I was typing on, not the next line.
For example, if the input that I type in is "3 4 + .", and the response from the computer is "7 ok", then I want the "7 ok" to be printed after my input, and only then go on to the next line, like this:
3 4 + . 7 ok
val @ . 66 ok
So, the newline is only started after the 'ok', not when I hit 'Enter'.
I've tried java.util.Scanner and something along the lines of
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Many thanks if anyone can help.
- 12-26-2010, 08:28 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
It's the operating system that manages a standard input stream (stdin for short) per process. The stdin is line buffered (note that you can press the backspace and have some simple editing facilities on that line). If you want to read from that stream unbuffered you have to tell the operating system to stop the buffering. In unixes (and linux) it's called 'raw mode' (the buffered mode is called 'cooked mode').
Setting the buffering style is an operating system thingy and it's beyond Java. You either have to run the 'stty' process in unix (linux) or use JNI code. There's also 'jcurses' (Google is your friend here) that can do it for you. Jcurses is Java code and has a documented API.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-26-2010, 10:03 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
ok. thanks. not straight forward then.
-
did you cross-post this on stackoverflow.com?
- 12-26-2010, 03:35 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Input from Command Line rather than from a text file
By thomas6 in forum New To JavaReplies: 3Last Post: 04-26-2010, 09:00 PM -
read a specific line in an input file
By sara12345 in forum Advanced JavaReplies: 7Last Post: 01-03-2010, 10:40 PM -
Multiple line user input
By jointhelabel in forum New To JavaReplies: 3Last Post: 10-26-2008, 02:41 AM -
Tip for System Defined line separator in a Batch File
By Java Tip in forum java.langReplies: 0Last Post: 04-04-2008, 02:48 PM -
Multiple Line Input Dialog Box
By johnt in forum AWT / SwingReplies: 2Last Post: 05-31-2007, 09:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks