Java Basics Series-Directory operations

Source: Internet
Author: User

Many of the ways in which Java operates on a directory are the same as in the previous file.

  

Java.io.File file = new file ("D:\1\2\3\4");

1. Creating a directory recursively

File.mkdirs ();

2. Deleting a directory

File.isdirectory (); Interpreting whether the table of contents

File.list (); Returns a file name without a full directory

File.delete (); Delete

3. Is the empty

File.list () > 0//Directory not empty

File.getpath (); Directory path

4. Determine if the directory is hidden

File.ishidden (); return type is Boolean

5. Directory hierarchy

File.getname (); Returns the name of the path name of the last name of the sequence

File.list (); Returns a file name without a full path

File.listfiles (); Returns the file name with the full path

6. Get the last modification time of the catalog

File.lastmodified ();

7. Get the parent directory

File.getparent ();

8. Get the Directory size

Org.apache.commons.io.FileUtils.sizeOfDirectory (file);

9. Get the current working directory

System.getproperty ("Uset.txt");

10. Show root directory

File.listroots ();

Java Basics Series-Directory operations

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.