Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How do I add datum to System.in from my program?

Reply
Thread Tools

How do I add datum to System.in from my program?

 
 
metfan
Guest
Posts: n/a
 
      10-25-2003
Hi,
Sorry, the title may not be clear. Let me describe my question.
I wrote a program to read from the console, say, System.in,

BufferedReader userInput = new BufferedReader(new
InputStreamReader(System.in));
String inputStr;
for (; {
try {
inputStr = userInput.readLine();
if (inputStr != null) {
System.out.println(inputStr);
}
} catch (Exception e) {
}
}

if the use input some data, for example, the user input
"Hello!" and press return, the code would print a line "Hello!",
now what I'm going to do is to simulate that the user has
input some extra data from console, for example, if the user
input "Hello!", the code above would print 2 lines:
Hello!
World!
And no, what I want is not a snip like:
try {
inputStr = userInput.readLine();
if (inputStr != null) {
System.out.println(inputStr);
}
inputStr = "World!";
System.out.println(inputStr);
} ...

What I really want is to simulate the date input by user from console,
did I make myself clear? and is that possible? sorry if my question
looks too newbie to you.





--
Best regards,
Qingjia Zhu
Q@z@J
 
Reply With Quote
 
 
 
 
Cory
Guest
Posts: n/a
 
      10-25-2003
metfan <qjzhupublic@___NoSpam__yahoo.ie> wrote in message news:<(E-Mail Removed)>...
> Hi,
> Sorry, the title may not be clear. Let me describe my question.
> I wrote a program to read from the console, say, System.in,
>
> BufferedReader userInput = new BufferedReader(new
> InputStreamReader(System.in));
> String inputStr;
> for (; {
> try {
> inputStr = userInput.readLine();
> if (inputStr != null) {
> System.out.println(inputStr);
> }
> } catch (Exception e) {
> }
> }
>
> if the use input some data, for example, the user input
> "Hello!" and press return, the code would print a line "Hello!",
> now what I'm going to do is to simulate that the user has
> input some extra data from console, for example, if the user
> input "Hello!", the code above would print 2 lines:
> Hello!
> World!
> And no, what I want is not a snip like:
> try {
> inputStr = userInput.readLine();
> if (inputStr != null) {
> System.out.println(inputStr);
> }
> inputStr = "World!";
> System.out.println(inputStr);
> } ...
>
> What I really want is to simulate the date input by user from console,
> did I make myself clear? and is that possible? sorry if my question
> looks too newbie to you.




Don't quote me on this but you could just use
System.setIn(yourInputStream)...
Remember, however to reset System.in if you want to be able to read
anythign from the console.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Canon PowerShot A710 IS - Datum verschwindet Axel Krebs Digital Photography 2 05-31-2007 08:48 PM
System Requirements: Trying to add USB2 to be able to use iPOD and add DVD Burner core Computer Support 3 05-04-2005 10:09 AM
naming a variable with the datum from another variable Duncan Harris Perl Misc 7 02-13-2005 06:48 PM
How to add shared assembly in the add reference babu dhayal via .NET 247 ASP .Net 2 08-17-2004 06:11 PM
How to write UTF-16 with BOM in little endian Von: Jean-Marc Autexier <jmau2002@web.de> Datum: Samstag, 30. August 2003 13:35:54 Gruppen: comp.lang.java.help Keine Referenzen Jean-Marc Autexier Java 2 08-30-2003 09:04 PM



Advertisments