This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
hi, i'm reading files from a zip file one by one and dispalying the o/p on the console in which a starnge thing happens. when i use System.out.write(x), it works fine but doesn't prints the last line of last file, but with System.out.print(char(x)), it works perfectly fine. i know System.out.write(x) writes bytes to stream, but in any case it should not skip the whole line. i'm baffled.
Basically, Java doesn't guarantee that output is actually sent to a file, socket, the screen, or any other output device until you call flush() on your OutputStream or Writer, or until it is closed. The OutputStream or Writer may buffer the output, meaning that it will be saved up and sent in larger chunks for efficiency. You can't really predict how this will be done.
PrintWriter.println() will automatically call flush(), by the way, although that doesn't matter here. But in any case, the general rule is that if you want output to appear somewhere immediately, and you're not using PrintWriter.println() (or PrintStream.println()), then call flush() yourself.
I have to write to the terminal ESC character. It doesn't work, but if I write instead of 27 ex. 51 it works.
System.out.write((byte)(27));Is NOK! System.out.write((byte)(51)); is OK!
I have another problem too: How to read from console one character without waiting for <CR>.
Thanks a lot.
System.out.write((int)(27)); Expected to output in Java the ESC symbol, but the system
catch the ESC symbol. Actually we needed to output two characters 'ESC' and '['
we can work this problem around instead of writing out two characters we can
output one character with the code (int) 155. See wikipedia.
So the problem was been solved. In "C" no characters will be catched. Why this is done
in Java I only can guess.