Java File class (reprinted Note)

Source: Internet
Author: User

Four File class definitions, a

1. The file class is the only object in the Java.io package that can represent the disk file itself, providing a "file" or "directory" Operation.

2. The file class defines some platform-independent methods for the operation of files, such as building, deleting, querying, renaming, and so On.

3, you can use it to indicate the name of a file, you can also use it to represent a group of files in the directory Name.

4, in the file class contains most of the functions and the operation of the method, the object of the class can represent a specific file or folder

File class constructor

Public File (String Path)

If path is a path that actually exists, the file object represents the directory

If path is a filename, the file object represents the

Public File (String path,string Name)

Path is the pathname, name is the file name

Public file (file dir,string Name)

Dir is the pathname, name is the file name

Processing of file names

String GetName ();//get The name of a file (not including the Path)

String GetPath ();//get The path name of a file

String GetAbsolutePath ();//gets The absolute path name of a file

String getParent ();//get The top-level directory name of a file

File Properties Test

Boolean exists ();//test the existence of the file indicated by the current file object

Boolean CanWrite ();//test whether the current file is writable

Boolean CanRead ();//test whether the current file is readable

Boolean isfile ();//test whether the current file is a file (not a Directory)

Boolean isdirectory ();//test whether the current file is a directory

Common file information and tools

Long LastModified (); Get the last time the file was modified

Long length (); Gets the length of the file, in bytes

Boolean Delete (); Delete current file

Directory Operations

Boolean mkdir (); Generates a path specified by the object based on the current object

String List (); List files in the current directory

Reprint Connection: http://www.mxiaoc.com/1218.html

Java File class (reprinted Note)

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.