When I use a statement like:
classLoader.loadClass()
What String am I putting inside the parentheses?
Is it:
1. The full absolute path to the class file?
2. A relative path to the class file (dependent on where the ClassLoader is made)?
3. Just the file name of the class?
4. Just the class name?
This is what I have been trying to work with so far:
public void scanFileSystem() throws ClassNotFoundException
{
if(packageName.startsWith("/"))
{
packageName = packageName.substring(1);
}
packageName = packageName.replaceAll("%20", " ");
File file = new File(packageName);
if(file.isDirectory())
{
for(File classFile : Objects.requireNonNull(file.listFiles()))
{
if(classFile.getName().endsWith(".class"))
{
Class c = loadClass(classFile);
if(c != null)
{
hiddenClasses.add(c);
}
}
}
}
else
{
System.out.println(packageName);
System.out.println("not a directory");
System.exit(0);
}
}
public Class loadClass(File file)
{
ClassLoader classLoader = Solution.class.getClassLoader();
if(file.getName().endsWith(".class"))
{
try
{
Class c = classLoader.loadClass(packageName + "/" + file.getName());
return c;
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
return null;
}
}
Needless to say, this doesn't work at all.