Java Utililty Methods File Name to Class Name

List of utility methods to do File Name to Class Name

Description

The list of methods to do File Name to Class Name are organized into topic(s).

Method

StringfileNameToClass(String fileName)
file Name To Class
return fileName.substring(0, fileName.length() - ".class".length()).replace('/', '.');
StringfileNameToClassName(String f)
file Name To Class Name
f = removeFromEnd(f, ".class");
f = removeFromEnd(f, ".java");
return f.replace('\\', '.').replace('/', '.');
StringfilenameToClassname(String filename)
filename To Classname
if (filename == null)
    throw new IllegalArgumentException("File name is null");
filename = filename.replace('/', '.');
filename = filename.replace('\\', '.');
if (filename.startsWith("."))
    filename = filename.substring(1, filename.length());
filename = filename.substring(0, filename.length() - 6); 
return filename;
...
StringfilenameToClassname(String fileName)
This method checks and transforms the filename of a potential Class given by fileName.
if (fileName.toLowerCase().endsWith(".class"))
    return fixClassName(fileName.substring(0, fileName.length() - 6));
return null;