Here you can find the source of renameFile(File file, String newName)
public static File renameFile(File file, String newName)
//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*/ }