Share this page 

Remove file extension Tag(s): IO



public static String removeExtension(String fileName) {

  int extPos = fileName.lastIndexOf(".");

  if(extPos == -1) {

    return fileName;

  }

  else {

    return fileName.substring(0, extPos);

  }

}

To rename an extension see this HowTo.