Possible Duplicate:
Best way to read structured binary files with Java
I used to be a c programmer. In c, if I want to transfer binary data (not just text file) from std io, I can just do it by calling getchar() and putchar()over and over again, until reaching EOF.
My question is that is that possible to do the same way in Java? Can I just call readline() and writeline() over and over again? If not, what can I do?
Thank you!
No, you should absolutely not use anything with
readLine()andwriteLine()calls. Those are for text data. If you’re transferring binary data, you should be usingInputStreamandOutputStream– nothing withReaderorWriterin the name. If you convert binary data to text, you’re almost guaranteed to lose data.But then you can just copy blocks of data at a time: