I have a project with sorting algorithms, I need to use a properties file to set the algorithm that I will use, my properties file looks like this:
sorter=metodosOrdenamiento.QuickSorterImpl
where "metodosOrdenamiento" is the package and "QuickSorterImpl" is my class. I'm trying this:
public static Sorter getInstance() throws IllegalAccessException, InstantiationException {
Properties properties = new Properties();
Class<?> myClass = null;
try {
properties.load(new FileInputStream("java_3/MiFactory.properties"));
myClass = Class.forName(properties.get("sorter").toString());
} catch (IOException | ClassNotFoundException e) {
System.out.println("No se pudo obtener la clase");
e.printStackTrace();
}
assert myClass != null;
return (Sorter)myClass.newInstance();
}
But it produces a "ClassNotFoundException", Which is the correct way to instantiate the class from the properties file?