ITeye博客

读取ar包中所有属性文件值

yanliebing · 2009-03-19 22:33 · java基础 · C · quartz · C++ · C# · Markdown

[code="java"]public class JarEntryTest { public static void main(String[] args) throws IOException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { JarFile jarFile = new JarFile("d:/quartz-1.6.5.jar"); Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class}); method.setAccessible(true); InputStream in = null; List lines = null; int c = 0; URLClassLoader classLoader = (URLClassLoader)ClassLoader.getSystemClassLoader(); method.invoke(classLoader, new Object[]{new URL("file:/d:/quartz-1.6.5.jar")}); Enumeration entrys = jarFile.entries(); while (entrys.hasMoreElements()) { JarEntry entry = entrys.nextElement(); String name = entry.getName(); if(name.endsWith(".properties")) { try { in = classLoader.getResourceAsStream(name); lines = IOUtils.readLines(in); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } for (String line : lines) { System.out.println(name + " " + line); } } } } }[/code] 了解这点后,对于读取国际化资源文件有所帮助 这里需要温习一下getdeclaredmethod getmethod之间的区别

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。