public static void main(String[] args) {
try {
Classloader cl = new Classloader();//你这是类加载器ClassLoader么?,还是你自定义的?
HttpURLConnection conn = (HttpURLConnection) cl.invoke(new URL("http://www.itheima.com"), "openConnection");
//不知道为什么不能这不写,提示是can not access a member of class sun.net.www.protocol.http.HttpURLConnection$HttpInputStream with modifiers "public"
//InputStream is = (InputStream)cl.invoke(conn, "getInputStream");Classloader,那来这么一个方法,没有把Classloader代码贴出来怎么看?
BufferedInputStream is = new BufferedInputStream((InputStream)cl.invoke(conn, "getInputStream"));
byte[] b = new byte[1024];
int len;
while((len = (Integer) cl.invoke(is, "read",b))!=-1){
//这里虽然能显示出来大部分的中文,但是也会有一些??出现,为什么呢?
System.out.println(new String(new String(b,0,len).getBytes(),"utf-8"));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Object invoke(Object clazz,String method,Object...objs) throws Exception{//这个好像与上面调用的无关?代码不全
Class cls = clazz.getClass();
Class[] clsx = new Class[objs.length];
for(int i = 0;i<objs.length;i++) {
clsx = objs.getClass();
}
Method me = cls.getMethod(method,clsx);
return me.invoke(clazz, objs);
}
请问你代表码全贴出来了么?
下面没注释的通过了? |