1 i/0: Input/output
1.1.java.io.file
1.2 Means: File or folder (directory)
1.3 File F = new file ("filename path");
1.4 Note: Relative paths: Non-web projects are relative to the project as a starting point. (Src/a.txt) Recommendations
Absolute path: D:/bin/a.txt (starts with a drive letter)
2. Common methods of documentation
Boolean flag = F.exists ();//File exists
Flag = F.isfile ();//Whether it is a file
Flag = F.isdirectory ();//Whether it is a directory
str = F.getpath ();//Get relative path to file
str = F.getabsolutepath ();//Get the absolute path to the file
str = F.getname (); Get file name
Flag = F.delete ();//delete file
Flag = F.createnamefile ();//Create File
Long = F.length ();//Return file length
Note: fle cannot manipulate file contents;
3.inputstream/outputstream
Files: FileInputStream
3.1 InputStream (input stream)
Data from file to Java code
int read (); Read one byte
int read (byte[]);//read a string of bytes
Long avaliable; File length
3.2 FileInputStream (byte file input stream)
New Fileinputsteam (File);
New FileInputStream ("File path + filename");
3.3 OutputStream (Input stream)
Data from Java code, written to file or other media
void write (bytes); Write a Byte
void Write (byte[]); Write byte array
3.4 FileOutputStream
New FileOutputStream (Flie);
New FileOutputStream ("File path + filename");
New FileOutputStream ("File path + filename", Boolean);
Note:A.boolean: Indicates whether to append to the end of the file, if true, to indicate
Append, False indicates no append (that is, overwrite). Default value is False
B. When creating an FileOutputStream instance
If the corresponding file does not exist, an empty file is created automatically
Java (file I/O)