Java tutorial
//package com.java2s; import java.io.File; public class Main { public static File convertFormat(File file, String newFormat) { StringBuilder tmpValue = new StringBuilder(file.getAbsolutePath()); int index = tmpValue.lastIndexOf(".") + 1; tmpValue.delete(index, tmpValue.length()); tmpValue.append(newFormat); File result = new File(tmpValue.toString()); return result; } }