本帖最后由 nestor 于 2014-4-16 09:14 编辑
代码:
- package fanShe;
- import java.io.*;
- import java.util.*;
- public class KuangJia {
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- InputStream ips = new FileInputStream("src\\fanShe\\config.properties");
- Properties props = new Properties();
- props.load(ips);
- ips.close();
- String className = props.getProperty("className");
- // System.out.println(className);
- Collection collections = (Collection) Class.forName(className).newInstance();
- String pt1 = new String("a");
- String pt2 = new String("b");
- String pt3 = new String("a");
- collections.add(pt1);
- collections.add(pt2);
- collections.add(pt3);
- collections.add(pt1);
- System.out.println(collections.size());
- }
- }
复制代码
报错:
- Exception in thread "main" java.lang.ClassNotFoundException: java.unil.ArrayList
- at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
- at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
- at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
- at java.lang.Class.forName0(Native Method)
- at java.lang.Class.forName(Class.java:190)
- at fanShe.KuangJia.main(KuangJia.java:16)
复制代码
config.properties:
- className=java.unil.ArrayList
复制代码
|
|