[Dark horse programmer Java training and Android training] I/O input/output stream video learning

Source: Internet
Author: User

/*
Requirement: JAVA applications must exchange data with external devices.
In JAVA, data input and output operations are performed in the stream mode.
JDK provides a variety of "stream" classes to operate on different types of data.
*/

1. File class File f = new File ("java. text ");
A File object represents a File or directory on the disk.
The File class provides platform-independent methods to process files or directories.
Example: If a file exists, it is deleted if it exists. If it does not exist, it is created.

2. RandomAccessFile class
Random access to files, with read/write methods.
The result of random access is obtained through skipBytes (int x) and seek (int x.
Example: The file contains information about three employees, which are printed in the order of second, first, and Third.

3. InputStream class ------------------> byte stream
Three read () methods.
Skip (long n) skips n Bytes
Available () returns the number of readable bytes
When the program processes data resources in real time, it is best not to use the avaliable () method, because it occupies too much CPU and always uses read (). When there is no resource, it will be blocked and almost no resource is occupied.
The close () method is not redundant for JAVA garbage collectors, because when an InputStream object is created, some resources will be generated in the operating system, but the garbage collector can only recycle object garbage.

4. OutputStream class
Three write () methods.
Flush () writes data to the buffer immediately
Close () writes data to the buffer and closes

5. FileInputStream and FileOutputStream
When creating a FileInputStream object, the specified file path should exist and be readable.

6. Reader and Writer class ----------------> producer stream
Used to read and write text files.
Text files are special cases of binary files.

7. PipedInputStream and PipedOutputStream
Used for inter-thread communication.
The PipedInputStream object of one thread reads the input from the PipedOutputStream object of another thread.
To make pipeline communication useful, you must construct both the pipeline input stream and pipeline output stream.

8. character encoding
 
The maximum ASCII bit is 0, which is identified by 7 digits;
GB2312 -- (extended) --> GBK

 

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.