Class FileRenamer

java.lang.Object
me.pauleff.common.handlers.files.FileRenamer

public final class FileRenamer extends Object
Renames files while optionally preserving the source file extension.
  • Method Details

    • renamePreservingExtension

      public static Path renamePreservingExtension(Path source, String newFileName) throws IOException
      Renames a file, preserving the original extension when the new name does not include one.

      If the source has an extension and newFileName does not end with that extension, the extension is appended. An existing file at the target path is replaced.

      Parameters:
      source - the file to rename
      newFileName - the desired file name, with or without an extension
      Returns:
      the path of the renamed file
      Throws:
      NullPointerException - if source or newFileName is null
      IOException - if the rename fails