java.io File Categories

Source: Internet
Author: User

The file is divided into binary format and text format.

Data is represented in binary form in computers, in general, bytes are the smallest logical unit of data, so it can be said that the data is represented in the form of a sequence of bytes, whether in memory or in a disk file. If the data in memory is written directly into the file, the resulting file is binary format, if all the data is treated as a sequence of characters, re-encoding according to the selected character set, and then write the result of the encoding to a file, the resulting file is text format.

For example, there is an int type of data, the value is 1234, in memory in the form of D2, the result of storing to the file can be as follows:

In the case of writing to a text file, choosing a different encoding scheme will have different results. Use a diagram to simply represent the IO process for the following text file:

There is a recoding problem with the text file, such as recoding 00_00_04_d2 (int 1234) in memory as UTF-8 to 31_32_33_34. character data and byte sequences need to have a character set as a mapping relationship, the character set is like a dictionary, encoding according to the character of the corresponding encoding, as a stored byte sequence, decoding the time according to the byte sequence to find the corresponding character, can be read by the person. Different character sets have different mapping relationships, so the character set and encoding used when decoding are consistent.

Characters in memory, of course, exist in a sequence of bytes, using Unicode encoding, and you can use integet.tohexstring (int) to get its contents. So writing character data to a text file, there is a transition from one character encoding result to another character encoding result.

java.io File Categories

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.