java- read from process while writing buffer
I have a program in which I call another separate program to do some works
(lets call it sub-process) , the sub-process takes some time to finish
each task and shows the progress in a simple console. the problem is, when
i try to read that console using BufferedReader , my own program waits for
the sub-process to finish before writing each line in a TextArea. here's
the code I'm using to read each line:
BufferedReader reader=new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while(line!=null)
{
report.append(line+"\n");
line=reader.readLine();
}
i tried to look into threads, but It still wouldn't work. how can I read
each line and add them to my textArea without waiting for the whole
sub-process to finish.
many thanks.
No comments:
Post a Comment