Here you can find the source of getFileNameWithNewExtension(File parent, File file, String ext)
public static File getFileNameWithNewExtension(File parent, File file, String ext)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static File getFileNameWithNewExtension(File parent, File file, String ext) { return isFileExists(new File(parent, file.getName()), ext); }// ww w .j av a2 s . com public static File isFileExists(String f, String ext) { return isFileExists(new File(f), ext); } public static File isFileExists(File f, String ext) { int point = f.getName().lastIndexOf('.'); if (point == -1) { point = f.getName().length(); } File lowerCasedFile = new File(f.getParentFile(), f.getName().substring(0, point) + "." + ext.toLowerCase()); if (lowerCasedFile.exists()) { return lowerCasedFile; } File upperCasedFile = new File(f.getParentFile(), f.getName().substring(0, point) + "." + ext.toUpperCase()); if (upperCasedFile.exists()) { return upperCasedFile; } return null; } }