A file is a major form of data storage in computing.
First, an absolute path and a relative path are introduced. The absolute path is the full path of writing, and the relative path is a partial path to the value writing file. D:\java\hello.java is the path to the data. Includes full path D:\java and full file name Hello.java, and relative path if file is executed under D:\ABC. The full path to the file is d:\abc\test.
In addition, the writing path in the Java language is. The file name distinguishes between uppercase and lowercase. Because "\" is a special character in the Java language, it is necessary to write a path when writing a c:\\abc\test\a.txt; Or two ways to write C:/abc/test/a.txt.
The following is an instance of creating a file:
Public File (String pathname); You can also use parent paths and sub-paths in conjunction with file F=new file ("d:\\test\\", "a.txt");
The following are some common methods of file.
①createnewfile creates the specified file. Only the file can be created, it cannot be used to create the directory, and the directory included in the file path must exist.
②delete Delete the current file or directory. If you delete a directory, the directory must be empty.
③exists, infers whether the current file or directory exists.
④getabsolutepath get the current file or ask Allison about the path, for example. C:\test\a.txt return to C:\test\a.txt;
⑤getname, gets the name of the current file or directory. Like C:\test\a.txt, back to A.txt.
⑥getparent gets the parent path in the current path.
⑦isdirectory infers whether the current file is a folder.
⑧isfile infers whether the current file object is a document.
⑨length returns the number of bytes that are consumed by the file store.
⑩list. The public String "" list () returns all the file names and directory names in the current directory. The name is not an absolute path.
11: listfiles, Public file "" Listfiles () returns the current directory to wash all of the files objects.
12: mkdir, Public Boolean mkdir () creates the current directory. Instead of creating other directories in the path, if the. There is a test directory under the D disk, and the creation of D:\TEST\ABC succeeds and returns True. Otherwise, false is returned.
13: Mkdirs: Creates a folder even if the parent folder does not exist. They will also be created on their own initiative.
14: Renameto, public Boolean renameto (file dest), change the filename. The file path cannot be changed.
If the file is already in the path, it fails.
File files for Java