File JavaO flow of operation

File:

File (file / folder address) constructor:

File public (String path);
public File (parentPath String, String childPath);
public File (File parent, String childPath);
File no constructor with no arguments. Because it is a system file or folder File representation. He assumed that no-argument constructor, then he by no parameters, then create an object, which represents the file or folder it?
Example 1: "Philosophy♂.txt"



example 2: "Philosophy♂.txt" changed to "./Philosophy♂.txt"


creation failed because Example 1 and Example 2 is the same.
Examples 3: "Philosophy / Philosophy♂.txt"



Example 4:


Example 5:

Method to create the file / folder: success returns true, otherwise returns flase


public boolean createNewFile (); // create a file
public boolean mkdir (); // create a directory of
public boolean mkdirs (); // create multi-level directory

detail:

Create a file, folder where this file must exist, do not exist on the error.

The name of the windows system folder and files are not case sensitive points.

folder windows system does not distinguish between separator / or 

File and folder name can not appear in the / \, so write with multiple delimiters, it is interpreted as a delimiter

File f = new File ( "d : ////////////AbC//////////////////a.txt"); // "/ "no parity number of points
File f = new File (" d : \\\\ AbC \\ a.txt "); //" number "must be double the number

Delete function:

java is deleted, do not take the Recycle Bin. + The Delete equivalent to the Shift
boolean the Delete ();
delete files: delete directly
delete the folder: first put the contents of the folder to be deleted before you can delete the empty folder.

Analyzing methods and acquired:

public boolean isDirectory (); // determine whether a File object is an object directory.
public boolean isFile (); // determine whether the object is a File object files.
public boolean exists (); // determines whether the File object represents a directory or file exists.
public String getAbsolutePath (); // get the absolute path of a file or directory.
public String getPath (); // get when you create a File object inside the constructor parameters.
public String getName (); // get the name of a file or folder without extension
all subfolders // directory can only be used to call the list method returns the directory (only one layer) under; public String [] list () or subdirectory name (String)
public file [] listFiles (); // can only be used to call directory listFiles method returns the directory (only one) all the sub-file or subdirectory (file) under

Recursively it returns all the absolute addresses in the directory for all files / folders:

Guess you like

Origin www.cnblogs.com/maomaodesu/p/11900420.html