File extension Utilities : File Name « File Input Output « Java






File extension Utilities

        



import java.io.File;

public final class FileUtil {


  public static String getFileNameWithoutExtension(File file) {
    return StripFileExtension(file.getName());
  }

  public static String StripFileExtension(String fileName) {
    return fileName.substring(0, fileName.lastIndexOf('.'));
  }

  public static String getExtension(File file) {
    return getFileExtension(file.getName());
  }

  public static String getFileExtension(String fileName) {
    return fileName.substring(fileName.lastIndexOf('.') + 1);
  }
}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Creates a file, making sure that its name is unique.