November 2006
Intermediate to advanced
224 pages
3h 29m
English
File file = new File("filename"); File dir = new File("directoryname"); boolean success = file.renameTo(new File(dir, file.getName())); if (!success) { // File was not successfully moved } |
The renameTo() method of the File class allows us to move a file or directory into a different directory. In this phrase, we create a File object to represent the file or directory we are moving. We create another File object representing the destination directory that we are moving the file or directory into. We then call the renameTo() method on the file being moved and pass it a single File object parameter. The File object passed as a parameter is constructed using the destination directory and the original file name. If the move ...
Read now
Unlock full access