• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why doesn't my InputStream have bytes.

 
Rodrigo Pimenta
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I built the code bellow to print some characters coming from a InputStream.
But, nothing is being printed. I guess my InputStream is empity.
What is wrong?
=====================
my code:
...
String s = new String("javac myFile.java");
Process processo = Runtime.getRuntime().exec(s);
BufferedInputStream in = new BufferedInputStream(processo.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
while ((s = reader.readLine()) != null) {
System.out.println(reader.readLine());
}
...
=================
Additional informatin: my code above doesn't rise exceptions.

Thanks in advance.
Rodrigo.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would you expect to get back from that command? Type it in at the console and see if you get anything back. Now if you were using a command switch that output data, like javac -verbose, then you would probably get something back.
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the program prints to standard out (you have to watch out for the occasional oddball printing to the error stream -- getErrorStream()), then your program will print every other line instead of every line. Take a close look at it to figure out why. You're certainly not the first person to make that mistake .
As a side note, using both a BufferedInputStream and a BufferedReader is unnecessary. A buffered stream just reads a few characters ahead and stores them in memory, which is very important for getting good performance during large IO operations. Buffering on two levels just increases the buffer size, which you can do manually with a constructor argument.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!