/** * Recursively lists the names of all files under the drive letter, such as E:\HeartIsland * * @author Heartisland * */public class Filelistdemo { /** * Recursively enumerates the names of all the files under the drive letter. If all the files under E:\HeartIsland are printed out, the path prints * * File File = new file ("e:\\heartisland\\"); * //List The path of the file * System.out.println (File.getpath ()); * //Inferred whether it is a directory * System.out.println (file.isdirectory ()); * //List A file or directory below a drive letter * */public static void Test (file file) { file[] files = file.listfiles () ; for (int i = 0; i < files.length; i++) { if (files[i].isdirectory ()) { test (files[i]); } else { Sys Tem.out.print ("Delete succeeded:" +files[i].getpath () + "\ T");//file path query and print System.out.print ("Run:" +files[i].delete () + "\ n ")///File run Delete (with return value)}}} public static void Main (string[] args) { file File = new file (" d:\\ Heartisland\\ "); Test (file);} }
Read permission class for file class:
public boolean canexecute ();//inference can be run enough
public boolean canRead ();//Infer whether the file is readable enough
public boolean canWrite ();//Infer whether the file is writable
public boolean createnewfile ();//Create a new file
public boolean Delete ()//delete file or directory
Public String GetAbsolutePath ();//Get the absolute path to the file
Public String getName ();//Get the name of the file
public string GetPath ();//change path name to string
public boolean isdirectory ();//Infer whether the file is a directory
public boolean isfile ();//Infer whether the file is a file
public boolean Ishidden ();//Infer whether the file is hidden
public long length ();//Returns the length of the file
Java recursive implementation deletes or queries all files under the specified directory