Java.io.File class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.