This is a trivial problem. The reason I'm here is to get a better idea of how to use Java's numerous APIs for working with files, folders, and paths. I'm hoping this specific example will help.
I want to rename a file like this:
I've been trying to find a concise way to do this, and this is the best I can come up with:
Files.move( Paths.get(file), Paths.get("/" + FilenameUtils.getPath(file) + FilenameUtils.getBaseName(file) + "_old" + FilenameUtils.getExtension(file)));
It works, which is why I'm not on Stack Overflow, but
- It's not portable because of the hardcoded "/".
- It's really cumbersome -- specifically I don't like how verbose
org.apache.commons.io.FilenameUtilsis, and how I have to convert my
I've looked at using
java.nio.file.Paths.resolve... but I haven't found anything tidy.