Java Reference
In-Depth Information
try {
Files.move(sourcePath, targetPath);
} catch (IOException e) {
e.printStackTrace();
}
How It Works
In the same manner as copying a file, create the path of source and destination. After
having the source and destination paths, Files.move will take care of moving the
file from one location to another for you. Other methods provided by the Files object
are the following:
Delete (path) : Deletes a file (or a folder, if it's empty).
Exists (path) : Checks whether a file/folder exists.
isDirectory (path) : Checks whether the path created points to a
directory.
isExecutable (path) : Checks whether the file is an executable.
isHidden (path) : Checks whether the file is visible or hidden in
the operating system.
8-8. Creating a Directory
Problem
You need to create a directory from your Java application.
Solution 1
By using the default FileSystem , you instantiate a path pointing to the new direct-
ory; then invoke the Files.createDirectory() static method, which cre-
ates the directory specified in the path.
Search WWH ::




Custom Search