Java Rename File renameSuffix(File f, String suffix)

Here you can find the source of renameSuffix(File f, String suffix)

Description

rename Suffix

License

Apache License

Declaration

public static File renameSuffix(File f, String suffix) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {

    public static File renameSuffix(File f, String suffix) {
        if (null == f || null == suffix || suffix.length() == 0)
            return f;
        return new File(renameSuffix(f.getAbsolutePath(), suffix));
    }/*from  w w  w  . ja  va2  s  .  com*/

    public static String renameSuffix(String path, String suffix) {
        int pos = path.length();
        for (--pos; pos > 0; pos--) {
            if (path.charAt(pos) == '.')
                break;
            if (path.charAt(pos) == '/' || path.charAt(pos) == '\\') {
                pos = -1;
                break;
            }
        }
        if (0 >= pos)
            return path + suffix;
        return path.substring(0, pos) + suffix;
    }
}

Related

  1. renameFiles(String rootDir, String sourcePostfix, String destPostfix)
  2. renameFolder(String destinationFolderPath, String zipFileName, String prefix)
  3. renameLocal(String oldPath, String newPath)
  4. renameOldFile(final String fileName)
  5. renameOverwrite(String oldname, String newname)
  6. renameTempDMLScript(String dmlScriptFile)
  7. renameTo(File currentFile, String newName)
  8. renameTo(File from, File to, boolean deleteDestination)
  9. renameTo(File fromFile, File toFile)