Here you can find the source of fileRenamer(final String fromPath, final String toPath, @Nullable final String toExtension, final boolean junkPaths)
public static Function<String, String> fileRenamer(final String fromPath, final String toPath, @Nullable final String toExtension, final boolean junkPaths)
//package com.java2s; //License from project: Apache License import javax.annotation.Nullable; import java.nio.file.*; import java.util.function.Function; public class Main { public static Function<String, String> fileRenamer(final String fromPath, final String toPath, @Nullable final String toExtension, final boolean junkPaths) { return new Function<String, String>() { @Override//from ww w . ja v a2 s. c om public String apply(final String path) { String name; if (!path.startsWith(fromPath) || junkPaths) { name = Paths.get(path).getFileName().toString(); } else { name = path.substring(fromPath.length()); } if (toExtension != null) { while (true) { final int index = name.lastIndexOf('.'); if (index < 0 || name.length() - index > 4) { break; } name = name.substring(0, index); } name = name + (toExtension.startsWith(".") ? "" : ".") + toExtension; } return toPath + name; } }; } }