Java.io.File class
1. Generally related to the input and output classes, interfaces, etc. are defined under the Java.io package
2.File is a class that can have constructors to create its objects. This object corresponds to a file (. txt. avi. doc. ppt. mp3. jpg) or the file directory
3.File class object is platform Independent. The methods in
4.File relate only to how to create, delete, rename, and so on. File is powerless as long as it involves the contents of the document and must be done by the IO stream. The objects of the
5.File class are often the parameters of the constructor of the concrete class of the IO stream.
① access filename
getName (): Returns the name of the file
GetPath (): Returns the path to the file
Getabsolutefile (): Returns the absolute file name
GetAbsolutePath ( ): Return absolute path
GetParent (): Return ancestor path
Renameto (file newName): Rename File1.renameto (file2): file1 must exist, file2 must not exist
② file detection
exists (): Determines whether a file or directory exists
CanWrite (): Returns whether the file or directory is writable
CanRead (): Returns whether the file or directory is readable
Isfile (): Determines whether the file object is a document
Isdirectory (): Determines whether the file object is a directory
③ Get general file Information
LastModified (): Returns the last modified time for a file or directory
Length (): Returns the size of a file or directory
④ file operations related
CreateNewFile (): Create a file
Delete (): Delete a file or directory
⑤ directory operation related
MkDir (): Create a file directory. Returns True
Mkdirs (): Creates a file directory only if the upper-level file directory exists. If the upper-level file directory does not exist, create a
list (): Returns all the contents of the folder as an array of strings
Listfiles (): Returns all contents of the folder as an array of files
Java.io.File class