Java basic self-study notes-Chapter 15: Binary I/O

Chapter 15: Binary I/O

Insert picture description here
Files can be divided into text or binary.
Text files are composed of character sequences, and binary files are composed of bit sequences.

1. The method of processing text I/O is to use the Scanner class to read text data and the PrintWriter class to write text data

Binary I/O does not involve encoding and decoding, and is more efficient than text I/O

2. Binary I/O class The
abstract classes InputStream and OutputStream are the root classes for reading and writing binary files
Insert picture description here
[Note]
There are four construction methods for fileOutputStream:

FileOutputStream(file:File)
FileOutputStream(filename:String)
FileOutputStream(file:File appen:boolean)
FileOutputStream(filename:String appen:boolean)

The first two construction methods, if the file does not exist, create the file, if the file exists, delete the file first, and the last two are to append data based on the existence of the file. Appen is true.

3. Random access file
java provides a RandomAccessFile class, which allows data to be read and written from any location in the file

RandomAccessFile raf=new RandomAccessFile("test.txt","r");//只读
RandomAccessFile raf=new RandomAccessFile("test.txt","rw");//可读写
InputStream//输入字节流

InputStreamReader//字节流转为字符流

BufferedReader//从字符流中读取文本

Binary I/O is not expanded, it will be gradually improved in the later stage, and then I will mention the characteristics of recursion:

  • Use if-else or switch statements to guide different situations
  • One or more base cases to stop recursion
  • Each recursion will simplify the original problem

The content of this chapter is less summarized, and it will continue to be improved in the later period, and the basic learning of java has basically come to an end. In the future, I will review the knowledge I have learned and take a look at my own notes.

Come on!

Guess you like

Origin blog.csdn.net/weixin_42563224/article/details/104651277