Java.io.File class
1. All classes and interfaces related to input and output are defined under the Java.io package
2.File is a class. Can have a constructor to create its object. This object corresponds to a file (. txt. avi. doc. ppt. mp3. jpg) or a file folder
The 3.File class object is platform-independent.
The method in 4.File only involves how to create, delete, rename, and so on. Only the contents of the file are involved. File is powerless. Must be completed by IO stream.
Objects of the 5.File class are often used as constructors for the detailed class of IO streams.
① Interview file name
GetName (): Returns the name of the file
GetPath (): Returns the path to the file
Getabsolutefile (): Returns the absolute file name
GetAbsolutePath (): Returns the absolute path
GetParent (): Return to Parent Path
Renameto (file NewName): Renaming of Files File1.renameto (file2): file1 must exist, file2 must not exist
② file Detection
Exists (): Infer whether a file or folder exists
CanWrite (): Returns whether the file or folder is writable
CanRead (): Returns whether the file or folder is readable
Isfile (): Infers whether the file object is a document
Isdirectory (): Infer whether the file object is a folder
③ Getting general file information
LastModified (): Returns the last modification time of a file or folder
Length (): Returns the size of the file or folder
④ file Operation related
CreateNewFile (): Create a file
Delete (): Deletes a file or folder
⑤ folder Operation related
MkDir (): Creates a file folder. Ability to return true only if the upper-level file folder exists
Mkdirs (): Creates a file folder. If the upper-level file folder does not exist, create
List (): Returns the entire contents of the directory as an array of strings
Listfiles (): Returns the contents of the directory in the form of an array of files
Java.io.File class