本帖最后由 吴亨 于 2012-2-9 20:11 编辑
package com.baidu.exam;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Properties;
public class HashTest {
public static void main(String[] args) throws Exception
{
Point p1 = new Point(1,1);
Point p2 = new Point(2,2);
Point p3 = new Point(1,1);
InputStream ip = HashSet.class.getResourceAsStream ("configure.properties");
Properties pro = new Properties();
pro.load(ip); //运行时,这句老是出错,出现空指针异常。配置文件和java类在一起。
ip.close();
String className = pro.getProperty("className");
Collection collection = (Collection) Class.forName(className).newInstance();
collection.add(p1);
collection.add(p2);
collection.add(p3);
System.out.println(collection.size());
}
} |