com.jpattern.util.FileUtil Maven / Gradle / Ivy
The newest version!
package com.jpattern.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
/**
*
* @author Francesco Cina'
*
* 21/lug/2010
*/
public abstract class FileUtil {
/**
* @param An absolute or relative file path
* @return the file name without the full path
*/
public static String removePath(String filename) {
final int pos = filename.lastIndexOf(File.separatorChar);
if (pos > -1) {
filename = filename.substring(pos + 1);
}
return filename;
}
/**
*
* @param filename a file name
* @return the file name without extension
*/
public static String removeExtension(String filename) {
final int lastindex = filename.lastIndexOf('.');
if ( lastindex != -1 ) {
return filename.substring(0, lastindex);
}
return filename;
}
/**
*
* @param filename a file name
* @return the extension of the file, an empty String otherwise
*/
public static String getExtension(String filename) {
final int lastindex = filename.lastIndexOf('.');
if ( (lastindex != -1) && (lastindex
© 2015 - 2025 Weber Informatics LLC | Privacy Policy