package com.chb; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; //继承URLClassLoader实现装载类的默认方法 public class ReadJarbbb extends URLClassLoader { public ReadJarbbb(URL[] urls) { super(urls); } public static void main(String[] args) { ReadJarbbb rj = null; try { // 注意url的格式,必需指定正确的协议file:不能使用纯路径. URL url = new URL( "file:C:/Users/Administrator/Desktop/SourceJarFile.jar"); rj = new ReadJarbbb(new URL[] { url }); // 反映出其中的类. Class c = rj.findClass("com.chb.UserInfo"); System.out.println(c); // 利用类进行jar文件中的资源的读取 InputStream in = c.getResourceAsStream("/file.txt"); byte[] bs = new byte[4096]; int length = -1; while ((length = in.read(bs, 0, 4096)) != -1) { System.out.println(new String(bs, 0, length)); } in.close(); } catch (MalformedURLException e2) { e2.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } // 这里不能传附件.... // 下面图片后缀。。。,你懂的.
转发请注明出处http://blog.martoo.cn
如有漏缺,请联系我 QQ 243008827
I’ve been surfing online more than three hours today, yet I never found any interesting article like yours. It is pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the web will be a lot more useful than ever before.