1. Create a folder or file reference:
File F = new file ("folder or file path");
Supplemental Note: The file or folder path is divided into absolute and relative paths
1> absolute Path: All file paths, including disk characters, specific directories, etc.;
2> relative path: Relative to a file path, for example, relative to Java engineering;
2, the creation of reference to the corresponding file:
F.createnewfile ();
3, create a reference to the corresponding folder:
F.mkdir (); Creating a single-tier directory
F.mkdirs (); Creating a multi-tiered Directory
4, to determine whether the reference to the corresponding file or folder exists:
F.exists ();
5, delete references to the corresponding file or folder:
F.delect (); When you delete a folder and there are subdirectories in the folder, you cannot delete it;
6, to determine whether the reference is a folder:
F.isdirectory ();
7, to determine whether the reference is a file:
F.isfile ();
8, to determine whether the reference file or folder is hidden:
F.ishidden ();
9, to determine whether the reference to the corresponding file or folder is readable:
F.canread ();
10, to determine whether the reference file or folder can be written:
F.canwrite ();
11, to determine whether the reference file or folder is executable:
F.canexecute ();
12, get reference to the corresponding file or folder size:
F.length (); The folder gets the method to get the size inaccurate, which requires the file clip directory to traverse the file size summation;
13. Get the absolute path to refer to the corresponding file or folder:
F.getpath ();
F.getabsolutepath ();
14. Get the parent directory that references the corresponding file or folder:
F.getparent ();
15, get references to the corresponding file or folder name:
F.getname ();
16. Get a collection of child files or subfolders that refer to the corresponding folder:
file[] flist = F.listfiles ();
eg. Get a. txt file that references the corresponding file
file[] Flist = f.listfiles (new FileFilter () {
Public Boolean accept (File pathname) {
Return Pathname.getname (). Endwith (". txt");
}
})
Where the anonymous object is filefilter as a file filter.
17. Rename the reference file or folder:
F.renameto (File F2);
The following is my use of the above methods to write a few of the folder operation of the packaging method links, including;
1, get all the files in the folder
2. Get all the files in the folder with the suffix of specific characters
3. Delete Folder
4. Cut Folder
Interested readers can click to read. Click to open the link