1.File only operates on the file itself, and if you want to manipulate its content, you need to use the Randomaccessfile class. (You need to receive the file class object, then proceed, remember closing close)
2. You can use byte stream (InputStream & OutputStream) and character stream (Writer & Reader) when no random access is required.
3. File operation process:
Open a file using the file class;
The output location is specified using subclasses of the byte stream and character stream (since the four operation classes, such as InputStream and writer, are abstract classes);
Perform read & write operations;
Close the file.
4. Byte stream: The main operation is data of type byte
InputStream (Input) && outputstream (output)
A byte type conversion is required between read and write: byte b[] = Str.getbytes ();
String str = new string (b);
Write is divided into: Append and overwrite two kinds, when outputstream instantiation is determined by the parameter.
5. Character stream: The string can be output directly, without the conversion of the format
Reader (read-in, input) && writer (output, write file)
6. The difference between the two:
The character stream is used in buffers (when the file is closed, the buffer contents are written to the file, or the flush () method is actively used for buffer emptying operations. The byte stream operates directly on the file itself and does not use buffers;
7. Generally use byte operations more, characters are only in memory will be formed, so the operation of using bytes is the most.
8. Also use byte stream: Read and write to prevent memory overflow (when the file is large).
Java IO Stream Learning