File copy of Java IO stream


File copy

Using byte stream to copy files

Here we need to know how the computer processes Chinese?

First, read a byte. If it is considered that there is no conversion, then the system processes Chinese according to the current encoding table [the first number of Chinese is generally negative]. When reading a byte, if it is an integer, it is directly converted to the character of the corresponding code table; If it is a negative number, judge the encoding table. Assume that GBK will wait for the next byte to be converted into corresponding characters. If it is UTF-8, it will wait for the next two bytes to be converted into corresponding characters.

File copy mode:

1. Copy a single byte


1. Create output stream object

2. Create input stream object

3. Define a byte to be used as an intermediate quantity

4. Cycle read and write

5. Close the flow

FileInputStream  fis=new FileInputStream(new File("E:\File\1.txt"));// Create input stream
2. Character array to copy


1. Create output stream object

2. Create input stream object

3. Create byte array

4. Get the length by byte array (length is used to judge and control the length of writing byte array)

5. Write the file from the byte array (if the length is not controlled, the default value in the byte array will be written if the last byte array is used up)

6. Close the flow

public static void main(String[] args) throws IOException {

This work adoptsCC agreementReprint must indicate the author and the link of this article

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]