• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Why doesn't my InputStream have bytes.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
His brain is the size of a cherry pit! About the size of this ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic