On FileInputStream and FileOutputStream input flow and output flow problems __java

Source: Internet
Author: User
The input stream, the output stream is exactly how to distinguish, in writing code often encounter problems, or often confusing to find two of the relationship between streams. Through today's study to make a note, but also to provide everyone to learn, at the same time ask me questions.

The book says
Input stream: Data can only be read from and cannot be written to.
Output stream: Data can only be written to it and cannot be read from.

So I have a question, what the hell is this stream?

The book on the definition of flow is: Java in the different input/output source (keyboard, file, network connection, etc.) abstract of the bid is "flow." So, the stream is the keyboard, file, network connection and so on is only abstracted.

Then take FileInputStream and FileOutputStream as examples to distinguish what is a stream. What is an input stream. What is an output stream.
public static void Test1 () throws exception{
        fileinputstream fileinputstream = new FileInputStream ("F:\\demo\\1.txt ");
        Create output stream
        fileoutputstream fos = new FileOutputStream ("F:\\demo\\2.txt");

        The definition character is used to receive the data read in the file
        byte[] bbuf = new byte[100];
        Define a hasread to determine the number of read data
        int hasread = 0;
        String line = "";
        while ((Hasread = Fileinputstream.read (bbuf)) > 0) {
            System.out.println (new String (bbuf, 0, Hasread));
            Writes the data read in the stream to the FOS stream to
            fos.write (BBUF);
        }
        Turn off the input stream
        fileinputstream.close ();
        Fos.close ();
    }
The function of this code is simply to read the data from the input stream and write it to the output stream.
so this input stream is 1.txt. The output stream is 2.txt
. The input stream (1.txt) reads the data from the previous input stream and the output stream definition. The output stream (2.txt) writes data to it.
in this case, the abstract flow is easy to understand.

Hope to have a better view of the following write their own profile for everyone to learn.

This article is a little ambiguous, I wrote an article, we look at it, you can clearly understand what is the input and output stream.

About FileInputStream and fileoutputstream input and output flow issues two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.