Java advanced video 02_io Input and Output 05 fileinputstream and fileoutputstream

Source: Internet
Author: User

Fileinputstream and fileoutputstream are used to create the input stream and output stream of the disk file respectively. The constructor is used to specify the file path and file name. Here, in and out are also relative applications.ProgramFor example, the file specified by fileinputstream exists and is readable. When the object fileoutputstream exists, it overwrites it. If it does not exist, it creates one, however, it cannot be a file that has been opened by other applications. Attach your own exercises.

The biggest drawback of fileoutputstream and fileinputstream is to replace the character with a byte before the operation. The class that directly operates the character is the writer and reader class, which is the abstract base class of all the livestream classes, it simplifies the programming of string input and output, that is, it is used to read text data. Differences between a binary file and a text file: without considering negative numbers, the data in each byte can be any number between 0 and 255, which is stored in binary format in the memory, A file is the storage format in which data in the memory is copied to the hard disk. Each data in the file is in the binary format, and the text character is composed of one or more bytes. However, the number of bytes cannot be any between 0 and 255 as in a binary file. It is a special number between 0 and 255, some numbers cannot correspond to any character in the data of other characters. If each byte or several adjacent data in a file can be expressed as one character, such a file is a text file. A text file is only a special case of a binary file. We convert a file other than a text file into a binary file, simply to include only text, other data without characters is called text files. Other files are binary files. Writer and reader are mainly used to read content in text format,

 

 

When writing a byte array, the byte array will automatically call the close method at the underlying layer, so you do not need to close it.

The characters read by filereader must be converted to strings. Therefore, it is not very easy.

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.