1. Introduction
The renameTo() method renames the file and returns true if the operation was successful. This method is heavily platform-dependent. It might not be able to move the file from one filesystem to another.
2. Method signature
Parameters:
- dest - the new abstract pathname for the named file
Returns
- true - if the renaming file succeeded; false otherwise
Throws
- SecurityException - when we do not have access to the file or directory
3. Examples
3.1. Snippet code that moves a file from path /tmp/exists.txt
to /tmp/ttt/dest.txt
The output:
4. Conclusion
In this article, we presented renameTo()
method available in the Java IO API that could be used to rename and also move a file to another directory.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}