Java File Rename renameFile(File file, String newName)

Here you can find the source of renameFile(File file, String newName)

Description

rename File

License

Open Source License

Declaration

public static File renameFile(File file, String newName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static File renameFile(File file, String newName) {
        String properPath = file.getPath().substring(0, file.getPath().lastIndexOf(File.separator));
        String newNameWithoutExt = newName.substring(0,
                newName.lastIndexOf(".") == -1 ? newName.length() : newName.lastIndexOf("."));
        return new File((properPath + File.separator + newNameWithoutExt + ".srt").replaceAll("\\s", "_"));
    }/*from  w  w w  .j a va 2 s.c om*/
}

Related

  1. renameFile(File file, String name)
  2. renameFile(File file, String newFilename)
  3. renameFile(File file, String newName)
  4. renameFile(File file, String newName)
  5. renameFile(File file, String newName)
  6. renameFile(File file, String sign, String suffix)
  7. renameFile(File source, File dest)
  8. renameFile(File sourceFile, String newFileName)
  9. renameFile(File src, File dest)