Overview of the File class (recursive)

Abstract representation of the path and file name

Construction method:

public File(string pathname)

To obtain a path according to a file object

public File(string parent,string child)

Get a file object based on a sub-directory and file / directory

public File(File parent,string child)

According to a File object to get a File object parent and a child file / directory

File class member method

Creating function

public boolean createNewFile()

public boolean mkdir()

public boolean mkdirs()

Delete function

public boolean delete()

Rename (if the pathname renamed to the same, if the path name to a different cut and renamed)

public boolean renameTo(File dest)

Delete function Note:

A: If you create a file or folder path forgot to write a letter, then the default in the project path

B: java recovery does not go in the trash

C: To delete a folder, note the folder does not contain a file or folder

Judgment function

Whether public boolean isDirctory () to determine the directory

public boolean isFile () to determine whether the file

public boolean exists () determines whether there

public boolean canRead () determines whether or not readable

Whether public boolean canWrite () judgment writable

public boolean is Hidden () to determine whether to hide

The basic acquisition function

public String getAbsolutepath () Gets absolute path

public String getPath () to get the relative path

public String getName () Gets the name

public long length () to get the length, the number of bytes

pubic long lastModified () Gets the last modified time value in milliseconds

Advanced acquisition function

public String [] list () Gets an array of all files or directories developed under the folder name

public File [] listFile () Gets File develop an array of all files or directories under the folder

The date format converted to milliseconds

Date d=New Data(123456789);

SimleDateFormat sdf=new SimleDateFormat("YYYY-MM-DD HH:MM:SS");

String s=sdf.format(d);

system.out.println(s);

Implement ideas and code file name filter

public String[] list(FilenameFilter filter)

public File[] listFiles(FilenmaeFilter filter)

Recursion:

Precautions:

1. recursion must be exported otherwise infinite loop

2. recursion can not be too much, otherwise memory overflow

3. The constructor can not be called recursively

 

Guess you like

Origin blog.csdn.net/qq_40935960/article/details/94959434