Programming architecture (04): javaio stream file management

Source code of this article: GitHub · click here | gitee · click here

1、 IO stream classification @ h_ 301_ 3 @ 1. Direction input stream of classification angle stream: the stream that reads data from the data source to the application; Output stream: a stream that writes data from an application to a destination; Stream data type byte stream: a stream that is read and written in the form of bytes. The identification is that the name ends in stream; Character stream: a stream that is read and written in character form. The identifier is a stream whose name ends with writer and reader; Pipeline flow: it is processed in data blocks, and the buffer is the data block used for reading and writing; Role of flow node flow: a flow that can read / write data from or to a node, also known as low-level flow; Processing stream: connecting or encapsulating existing streams and reading / writing encapsulated streams, also known as high-level streams. 2. The API system has five core classes objectoutputstream: file, OutputStream, InputStream, writer and reader; 1. Key interface: serializable;

2、 API detail classification @ h_ 301_ 3 @ 1. Byte input stream InputStream: byte input stream is the parent class of all byte input streams. It provides a standard and basic method and simple implementation related to reading bytes for all byte input streams. FileInputStream: the file byte input stream reads the data in the file into the application in the form of bytes; Bufferedinputstream: buffered byte input stream, which provides buffering function and improves efficiency; Bytearrayinputstream: the byte array input stream is used to read the bytes in its built-in cache byte array; Pipedinputstream: pipe byte input stream must be used in combination with pipedinputstream for communication between threads; Filterinputstream: filter byte input stream, override InputStream method, and provide extension for byte input processing stream; Datainputstream: data byte input stream, which is generally used in combination with dataoutputstream; Objectinputstream: object byte input stream, used in combination with objectoutputstream; 2. Byte output stream OutputStream: byte output stream has the same function as InputStream. It provides a standard for all byte output streams and defines some methods and simple implementations of basic output bytes; Fileoutputstream: File byte output stream, which writes bytes to the file source of the specified destination; Bufferedoutputstream: buffered byte output stream, providing buffering function and improving efficiency; Bytearrayoutputstream: byte array output stream, which writes bytes to a built-in cache byte array carried by itself; Pipedoutputstream: piped byte output stream, which must be used in combination with pipedinputstream for communication between threads; Filteroutputstream: filter byte output stream and provide extension for byte output processing stream; Dataoutputstream: data byte output stream, which is generally used in combination with datainputstream; Objectoutputstream: object byte output stream, usually used in combination with objectinputstream; Printstream: byte print stream, which is decorated with byte output stream and provides the function of printing various data types; 3. Character input stream reader: character input stream, which provides a standard definition and simple implementation of only basic reading methods for all character input streams; Inputstreamreader: byte conversion stream, which converts byte stream into character stream, and can specify the encoding used when converting bytes into characters; BufferedReader: buffered character input stream, which provides buffering function for character input stream and improves efficiency; Chararrayreader: character array input stream, which reads the data in its built-in character cache array into the application; Pipedreader: pipeline character input stream, which is used in combination with pipedwriter for communication between threads; Filterreader: filters the character input stream and provides extensions for the character input stream; FileReader: file character input stream, which reads the contents of the file in the form of characters; 4. Character output stream writer: character output stream. All character output streams provide a standard, basic writing method and simple implementation; Outputstreamwriter: byte output conversion stream, which is used to convert byte output stream into character output stream. Code conversion can be specified; Bufferedwriter: caches the character output stream to provide buffering function and improve efficiency; Chararraywriter: character output stream, used to write characters into its built-in cache character array; Pipedwriter: piped character output stream, used in combination with pipedreader, for communication between threads; Filewriter: file character output stream, used to write characters to a specified file; Printwriter: character print stream, which prints various data in the form of characters;

3、 File class @ h_ 301_ 3 @ 1. Construction method file (string pathname): specify the path of a file or folder to create a file file; File (file parent, string child): create a new file instance according to the parent abstract pathname and child pathname characters; 2. Path problem absolute path: the full path of the file on the hard disk. Absolute paths usually start with a drive letter. Relative path: the relative path is the path of the resource file relative to the current program Current path Upper level path 3. File creation createnewfile(): creates an empty file at the specified location, returns true successfully, does not create if it already exists, and then returns false; Mkdir(): create a directory at the specified location, which will only create the last level directory. Throw an exception if the parent directory does not exist; Mkdirs(): create a directory in the specified location, which will create all nonexistent directories in the path; 4. Delete file delete() deletes a file or an empty folder. If the folder is not empty, it cannot be deleted. Success returns true and failure returns false; 5. Judge method exists (): whether the file or folder exists; Isfile(): whether it is a file. If it does not exist, it is always false; Isdirectory(): whether it is a directory. If it does not exist, it is always false; 6. Get file information getname(): get the file or folder name, excluding the parent path; Getpath (): returns an absolute path, which can be a relative path, but the directory should be specified

4、 Encoding and decoding @ h_ 301_ The 3 @ byte stream reads the binary data in the file and will not be automatically converted to understandable characters; Character stream: encode and decode the read data.

5、 Source code address @ h_ 301_ 3 @ GitHub · address

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>