I/O flow in the file class common methods (2)

Source: Internet
Author: User

5, folder Related:
1) staic file[] Listroots () lists all the root directories (the letter for All systems in window)
Example:

File[] roots = File.listroots (); Lists all the root for
    (file file  : Roots) {
        System.out.println (file);
    }

2 list () returns the file or directory name in the directory containing the hidden files. This action returns null for the file.
Example:

string[] FileNames = File.list (); 
/* Stores all child file names and subfolder names below the current folder in a string type array. */For
    (String filename:filenames) {
        System.out.println (fileName);   
    }

3) Listfiles () returns a file or directory object (instance of the file class) in the directory containing hidden files. This action returns null for the file.
Example:

file[] files = file.listfiles (); /* Use a File object description for all subfolders and subfolders below the current folder, and then store the file objects in a file array to return the */for
    (file fileitem:files) {
        System.out.println ("Wennan:" +fileitem.getname ());
    }

4) List (FilenameFilter filter) returns a child file or subdirectory that matches the filter criteria in the current directory. This action returns null for the file.
5) Listfiles (FilenameFilter filter) returns a child file or subdirectory that matches the filter criteria in the current directory. This action returns null for the file.
Example:

The two methods are similar, except that the return value of the list is of type string.

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.