To improve I/O performance, it is primarily based on the following principles:
(1) Less access to the disk as little as possible
(2) Less access to the underlying operating system to access the underlying operating system as little as possible
(3) Less method calls to minimize method calls
(4) Can less individual processing byte characters as little as possible individual processing.
Tip 1: Use buffering to access the buffer as much as possible
For example, Character-based has BufferedReader, bufferedinputstream based on byte. Or you can use block-reading methods to improve performance.
Skill 2:inputstream is more efficient than reader, outputstream is more efficient than writer
Skill 3:byte is more efficient than char
A char holds the characters in 2 bytes, but a byte saves the data in only 1 bytes. In addition, byte can avoid Unicode conversions.
Tip 4: Buffer blocks are more efficient than buffer streams
Although buffer streams are more efficient than individual character accesses, they involve multiple method invocations, and buffer blocks are much more efficient than buffer streams.
Tip Close Stream in 5:finally
The various resources used in the program are closed in time, and finally blocks are the best places to close. Because finally blocks are always executed.
Tip 6: Release large object resources early and in time
such as database connection resources, and then closed in time, too long for the system overhead too much.