rulla101
rulla101

Reputation: 19

Moving a Directory to a higher Directory in Java?

I have a folder called "data". It's in a subdirectory of my system, lets say in "big folder." I want to move the data folder out to my home folder, or "user." So the data folder's path is user/big folder/data. How do I move it out?

Upvotes: 0

Views: 124

Answers (1)

Alexander Pavlov
Alexander Pavlov

Reputation: 32306

You should play around with the following snippet (not tested):

File src = new File("user/big folder/data");
File dest = new File("user");

boolean success = src.renameTo(new File(dest, src.getName()));
if (!success) {
    // Directory was not successfully moved
}

Upvotes: 1

Related Questions