Package CN. itcast. day2;
Import java. Io. inputstream;
Import java. util. collection;
Import java. util. properties;
Public class classlodertest {
Public static void main (string [] ARGs ){
// How to dynamically obtain the storage path of the configuration file (not manually specifying the absolute path)
// The class loader can be used for loading, but this method is read-only and cannot be used to operate the loaded configuration file.
// 1. Obtain the path of the configuration file
// Get it through the Class Loader
// Inputstream IPS = reflecttest. Class. getclassloader (). getresourceasstream ("cN/itcast/day1.config. Property ");
IPS = reflecttest. Class. getresourceasstream ("config. Property") // the method provided by the class itself
// In practice, the configuration file will be placed in a special folder, such as resource, which should be written in this way
// IPS = reflecttest. Class. getresourceasstream ("resource/config. Property ")
Properties pros = new properties ();
Pros. Load (IPS );
IPS. Close ();
String classname = pros. getproperty (classname );
Collection collections = (Collection) class. forname (classname). newinstance ();
}
}