Java Core Technology Volume II (i)

Source: Internet
Author: User

Book: "Java Core Technology Vol. two advanced features 9"

Time: 2017.9.4-17:13

1. Flow

Input stream: An object from which a sequence of bytes can be read; abstract class (InputStream)

Output stream: An object to which a sequence of bytes can be written; abstract class (OutputStream)

Source of the stream: file, network connection, memory block.

Byte-oriented, so it is inconvenient to process Unicode information (multiple bytes per character)

-->reader & Writer extends Stream (implements two byte characters)

InputStream Method:

abstract int Read (): reads a byte and returns the read-in byte, which returns 1 at the end. The subclass needs to override this method.

abstract int write (int b): writes out a byte to a location.

Note: These two methods block the thread at execution time until the read-in or write-out is complete.

Available: Check the current number of bytes that can be read in

Flush: Outputs the stream of the buffer.

After reading and writing, you must call the Close method to close the stream, or if it flows more, it will run out of operating system resources.

FileInputStream & FileOutputStream can provide input and output streams attached to a disk file. The parameter is a file name or full pathname.

Use System.getproperty ("User.dir") to get the current path

System. out. println (System.getproperty ("user.dir")); -D:\WorkSpace\Eclipse\IOTest

The full path we need to get the operating system operator, such as under Windows:

System. out. println (File.separator); -/    

You can also use the double backslash notation: c:\\windows\\123.txt

A basic read-file program:

ImportJava.io.FileInputStream; Public classIotest { Public Static voidMain (string[] args) {Try{FileInputStream FileInputStream=NewFileInputStream ("D:\\workspace\\eclipse\\iotest\\123.txt"); inti =fileinputstream.available ();  for(intj=0;j<i;j++) {System.out.printf ("%c", Fileinputstream.read ());        } fileinputstream.close (); } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); }    }}

Java Core Technology Volume II (i)

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.