Java method for creating and deleting files and directories (recommended)
Methods for creating and deleting file classes commonly used in files / directories
1. Boolean exists(): judge whether the file or directory exists Boolean createnewfile(): create a new file 3 Boolean delete(): delete the file 4 Boolean mkdirs(): create multilevel directories recursively 5 File getparentfile(): get parent directory
1. Create / delete files
• create directory
File operation
1. String getname(): get the file name 2 Long length(): get the file size and return the byte unit of 3 File getparentfile(): get the file object of the parent directory 4 String getparent(): get the parent directory path 5 Long lastmodified(): last modified 6 Boolean isfile(): is it a file
Operation of directory
1. String [] list(): get the string representation of all files in the directory
2. File [] listfiles(): get the file representation of all files in the directory
3. Boolean isdirectory(): is it a directory
Recursive output directory
The program calls itself
summary
The above is the method of creating and deleting files and directories in Java introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!