| Author |
How to use PipedReader,pipeWriter, i has error output
|
eric lee
Ranch Hand
Joined: Nov 04, 2002
Posts: 86
|
|
Why i can not output A,B,C? i got output "Error" so how to change code? Thanks ------------------------------------------------- import java.io.*; class test { public static void main(String args[]) { PipedWriter out=new PipedWriter(); PipedReader input=new PipedReader(); char buffer[]={'A','B','C'}; int inChar; try{ inChar=input.read(buffer); while(inChar!=-1) out.write(buffer,0,inChar); }catch(IOException e){ System.out.println("Error");} } }
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
What kind of error did you get? Was it a compiler error? Was it a runtime error? What did the error message say?
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
eric lee
Ranch Hand
Joined: Nov 04, 2002
Posts: 86
|
|
|
the code got to excpetion and print "Error"
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
I'm new to Java IO too, but I see these things: 1) Your PipedReader and PipedWriter have to be connected. 2) You should probably be writing into your PipedWriter before you read from your PipedReader. 3) Pipes are normally used between different threads
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Maybe this does what you are expecting: Thank you for giving me the opportunity to learn about Piped IO and threads. [ April 02, 2003: Message edited by: Barry Gaunt ]
|
 |
eric lee
Ranch Hand
Joined: Nov 04, 2002
Posts: 86
|
|
|
Thanks Barry Gaunt , i learn too!
|
 |
 |
|
|
subject: How to use PipedReader,pipeWriter, i has error output
|
|
|