Java Reference
In-Depth Information
Invoke the System class's getProperty method. For example:
String path = System.getProperty("user.dir");
How It Works
When a Java program starts, the JRE updates the user.dir system property to record
where the JRE was invoked. The solution example passes the property name
"user.dir" to the getProperty method, which returns the value.
8-6. Copying a File
Problem
You need to copy a file from one folder to another.
Solution
From the default FileSystem , you create the “to” and “from” paths where the files/
folders exist and then use the Files.copy static method to copy files between
the created paths:
FileSystem fileSystem = FileSystems.getDefault();
Path sourcePath = fileSystem.getPath("file.log");
Path targetPath = fileSystem.getPath("file2.log");
System.out.println("Copy from
"+sourcePath.toAbsolutePath().toString()+
" to "+targetPath.toAbsolutePath().toString());
try {
Files.copy(sourcePath, targetPath,
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
e.printStackTrace();
}
Search WWH ::




Custom Search