Loubna Laraje
Loubna Laraje

Reputation: 17

how to save file path after move it from a directory to another in java

I copy a file from a directory for another but I have a difficulty to find the new file path ! I used FileUtils class from apache commons-io library to do that..... please is that there a function can save the last file path ?

Upvotes: 1

Views: 147

Answers (1)

om-nom-nom
om-nom-nom

Reputation: 62835

Since FileUtils.moveFile accepts two arguments -- source file and destination file, all you need to do is to use second arg:

File myFile = new File("file");
File newLocation = new File("funky_file");
FileUtils.copyFile(myFile, newLocation);
myFile = newLocation;

You cannot retrive new location basing only on myFile without reassigning: File class is designed to be a immutable path rather that hard link to the file.

Upvotes: 1

Related Questions