Languages
[Edit]
EN

Java - rename or move file

0 points
Created by:
Huzaifa-Ball
475

In this article, we would like to show you how to rename or move file in Java.

We use Files.move() method both to rename or move a file to a target file.

1. Rename file

Edit

In this example, we use Files.move() method to rename example.txt file to newName.txt.

2. Move file

Edit

In this example, we use:

  • Files.createDirectories - to create the directory if doesn't exist,
  • Files.move - to move the file under specified path (source) to the new directory (target).

Practical example:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join