This commit is contained in:
Ziver Koc 2011-09-14 17:02:06 +00:00
parent 47849b61ec
commit eb5911ac7d
4 changed files with 23 additions and 6 deletions

View file

@ -281,7 +281,7 @@ public class FileUtil {
}
/**
* Returns the extension of the file
* Returns the extension(without the dot) of the file. e.g. "png" "avi"
*
* @param file is the file
* @return The extension
@ -291,5 +291,20 @@ public class FileUtil {
return "";
return file.substring(file.lastIndexOf(".")+1, file.length());
}
/**
* Replaces the current extension on the file withe the given one.
*
* @param filename is the name of the file
* @param string is the new extension, without the dot
* @return
*/
public static String changeExtension(String file, String ext) {
if( file == null )
return null;
if( file.lastIndexOf(".") == -1 )
return file+"."+ext;
return file.substring(0, file.lastIndexOf(".")+1)+ext;
}
}