First, the file class
The file class is an abstract representation of the path names of files and directories. File is used only as a surface for a file or directory and cannot be modified for the contents of a document.
Common methods in the file class:
- When the user accesses, operates the file or the directory, usually has the readable, the writable, the executable three kinds of permissions, may through the file class CanWrite (), CanRead (), CanExecute () judgment.
- CreateNewFile () When a file with that name does not already exist, create a new file that is named after the abstract path name.
- Exists () determines whether the file exists.
- Delete () deletes the file or directory.
- GetName () Gets the file or directory name.
- Isdirectory () is a directory.
- mkdir () Creating a directory
- Mkdirs () Creates a directory that contains a directory that does not exist at the parent level.
- Renameto () renames a file or directory.
- List () returns an abstract array representing the files or directories in the directory.
Second, I/O
The I/O classes in the Java class Library are divided into two parts, input and output, and all classes related to the input should inherit from InputStream, and the output-related classes should inherit from OutputStream.
For text files read and write, in the form of a character stream. For binary storage of the file slices, video, word and so on in the form of byte stream read.
BYTE stream
InputStream
FileInputStream
Filterinputstream:datainputstream Bufferedinputstream
ObjectInputStream
OutputStream
FileOutputStream
Filteroutputstream:dataioutputstream Bufferedoutputstream
ObjectOutputStream
Character Stream
FileReader
BufferedReader
FileWriter
BufferedWriter
Conversion between a byte stream and a character stream (conversion stream)
InputStreamReader:
Converts a byte array into a character reader in the program, which is also called decoding.
Outputstreamreader
Writes a string to a byte array into a text file, which is encoded.
Java I/O fundamentals