iostream « API « Java I/O Q&A

1. Java - open existing file or create one if doesn't exist using IO streams

I was following instructions from a Java website ( on creating or writing a file using an IO stream. However, the code it provides seems to be broken in ...

2. byte stream and character stream

Please explain byte stream and character stream files. What exactly these means , is microsoft word document is byte oriented or character oriented ? Thanks

3. In Java: why some Stream methods take int instead of byte or even char?

Why some methods that write bytes/chars to streams takes int instead of byte/char?? Someone told me in case of int instead of char: because char in java is just 2 bytes length, which ...

5. coping streams - nio's channels vs. io

Are NIO's Channels faster than IO's inputstreams/outputstreams when you want to copy one stream to another? if not when you would use channels?

6. How should I handle third-party input/output streams?

There is a piece of project dealing mostly with input/output streams. So I have to pass streams as arguments and receive them from third-party libraries. I've read Good design: How ...

7. Why character streams?

I understand that Java character streams wrap byte streams such that the underlying byte stream is interpreted as per the system default or an otherwise specifically defined character set. My systems default ...

8. Convert InputStream into FileInputStream

I have read this post How to convert InputStream to FileInputStream on converting a InputStream into a FileInputStream. However, the answer does not work if you are using a resource ...

9. What is the proper way to write/read a file with different IO streams

I have a file that contains bytes, chars, and an object, all of which need to be written then read. What would be the best way to utilize Java's different ...

10. how to end streamtokenizer loop when reading tokens?

I know "while (((str.nextToken()!=str.TT_EOL)))" is an infinite loop, but I want to know how can I end this loop in a similar way that in StringTokenizer as "while (st.hasMoreTokens())", it ...

11. java: Do I need to close all the streams?

I have a method that reads text from a file; decompression may be required, depending on an input parameter:

public static String readText(File inFile, boolean compressed) {
    InputStream in ...

12. How to Send a Password to Process in Java

I am launching a process from java to run a command for me. This process runs for a little while, then needs a password to continue. Now I know that I ...

13. Java I/O read Delay

When i try to read the InputStream , the reading takes a lot of time from the server . The process reads some bytes pauses for 5 mins , reads again ...

14. Java: transformation from byte to char and how to use dataOutputStream


public class TestEOF {
    // Throw exceptions to console:
    public static void main(String[] args) throws IOException {

15. How to clear/reset/open an input stream so it can be used in 2 different methods in Java?

Here's the code:

    package testpack;

    public class InputStreamReadDemo {

        private void readByte() throws ...