Commonly used method in Java File object

Created:
  1, createNewFile () to specify the location to create an empty file, success returns true, if there is not already created, and then returns false.

  2, mkdir () to create a single-level folder in specified location.

  3, mkdirs () to create a multi-level folder in specified location.

  4, renameTo (File dest) If the destination and source files are in the same path, then renameTo role is renamed, the target file if the source file is not in the same path, so the role is renameTo

  Cut, but can not operate folder.


Delete:
  the Delete () to delete a file or an empty folder, you can not delete non-empty folders, delete files immediately return a Boolean value.
  Delete deleteOnExit () when jvm exit the file or folder to delete temporary files, no return value.


Judging:
  EXISTS () the file or folder exists.
  isFile () whether it is a file, if not present, is always false.
  isDirectory () is a directory, if not present, is always false.
  isHidden () whether it is a hidden file or whether it is a hidden directory.
  isAbsolute () to test whether this abstract pathname is absolute pathname.


Gets:
  getName () Gets the name of the file or folder does not contain the higher path.
  whether absolute path getAbsolutePath () Gets a file, the file exists and it does not matter
  the size of the length () Gets the file (in bytes), if the file does not exist return 0L, if the folder is also returns 0L.

  getParent () Returns the parent directory pathname of this abstract pathname string; if no parent directory pathname, or null.
  lastModified () Gets the last time it was modified.


Folder Related:
  static File [] listRoots () lists all the root directory (Window of the letter is all systems)
  List () returns the file or directory name in the directory, including hidden files. For such action file will return null.
  the listFiles () file or directory object (File class instances) returns under the directory, including hidden files. For such action file will return null.

  list (FilenameFilter filter) Returns the specified sub-file or subdirectory in the current directory that meet the filter criteria. For such action file will return null.

  listFiles (FilenameFilter filter) Returns the specified sub-file or subdirectory in the current directory that meet the filter criteria. For such action file will return null.

Guess you like

Origin www.cnblogs.com/LixiaoFeng1650062546/p/11078888.html