![]() |
The createTempDirectory() method of java.nio.file.Files Class is used to create a new directory using the given prefix and attributes. The given prefix acts as the name of the formed directory, may be null. The directory is set with given attributes. Based on the type of arguments passed, the Files class provides 2 types of createTempDirectory() method. Methods: 1. public static Path createTempDirectory(Path dir, String prefix, FileAttribute<?>… attrs): This method is used to create a new directory in an already existing directory, using the given prefix to generate its name. The path of the newly formed directory is associated with the default FileSystem. Which is the same as the path of the specified directory. The candidate names are generated using the prefix. The File.deleteOnExit() method is used to delete the directory automatically. The attrs parameter is used to set attributes of the directory. Each attribute is identified by its name. If there is more than one attributes is specified with the same name then all the occurrences except the last one are ignored. Parameters:
Returns: path of the newly formed directory Exception:
Java
Output: Temporary Directory created at: /usr/local/bin/directory/TempDirectory1472243991754401317 2. public static Path createTempDirectory(String prefix, FileAttribute<?>… attrs): This method is used to create a new directory using the given prefix and attributes. The given prefix acts as the name of the formed directory, may be null. The candidate names are generated using the prefix. The directory is set with given attributes. The path of the newly formed directory is associated with the default FileSystem. The attrs parameter is used to set attributes of the directory. Each attribute is identified by its name. If there is more than one attributes is specified with the same name then all the occurrence except the last one is ignored. Parameters:
Returns: path of the newly formed directory Exception:
Java
Output: Temporary Directory created at: /var/folders/13/jsq29lh11bn7kgwnzpggqytr0000gn/T/TempDirectory4403940384431706243
|
Reffered: https://www.geeksforgeeks.org
Java |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 9 |