Java-io Package of Learning Guide article (excerpt)

Source: Internet
Author: User
Tags interface log
What is IO io (input/output) is the output/output interface of the computer. Java's core library java.io provides a comprehensive IO interface, including: file reading and writing, standard device output, and so on. In Java, IO is input and output based on streaming, all data is serialized to the output stream, or read from the input stream. In addition, Java also provides support for block transfers, with block IO in the core library Java.nio.  About NIO We have a special discussion behind it. The benefits of streaming Io are simple and easy to use, and the disadvantage is low efficiency. Block IO is highly efficient, but programming is more complex. Java IO model Java IO Model design is very good, it uses the decorator mode, the function of the stream, you can dynamically assemble these stream, in order to get the functionality you need.  For example, if you need a file input stream with buffering, you should use FileInputStream and bufferedinputstream in combination. The Java IO system is divided into two categories Input/output and Reader/writer, the difference is that Reader/writer can automatically convert the inner code when reading and writing text. Basically, all IO classes are paired, that is, there is a corresponding xxxoutput in the xxxinput. Java IO Tutorial If you know the decorator mode very well, you can easily see the Java IO class structure: The root interface is Inputstream/outputstream, the IO class that acts as a data source has fileinputstream/ Fileoutputstream,bytearrayinputstream/bytearrayoutputstream and so on, as the decorative function of the IO class has bufferedinputstream/ Bufferedoutputstream,datainputstream/dataoutputstream and so on, they are inherited decorative interface Filterinputstream/filteroutputstream. When you use IO, you first create a data source Io, and then create the decorative class IO based on the functionality you want, and its constructor parameters are the data source IO you have created. Let's take the example of creating a buffered file input stream, assuming that you need to read the file "C:\log.txt" from disk://Create a Fileinputstream:fileinputstream fileInput = new FileInputStream ( "C:\\log.txt"); Create a Bufferedinputstream:bufferedinPutstream bufferedinput = new Bufferedinputstream (fileInput); The bufferedinput that is now available is a buffered file input stream or further abbreviated as follows: InputStream input = new Bufferedinputstream (    new FileInputStream ("C:\\log.txt"); the input is now buffered file input stream after you have a general understanding of Java Io, we recommend that you take a look at the tutorials introduction to Java I/O and I/OS: Reading and writing. Java NIO Programming NiO provides support for block IO, the advantage of using block IO is more efficient, and Java NiO will directly invoke many of the advanced IO interfaces provided by the operating system, support block transfer, read-write locking, asynchronous IO and other functions, very efficient. The programming model for NIO is the channel and buffer, and it is recommended that you read getting started with new I/O (Chinese).

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.