---
title: "读取ar包中所有属性文件值"
author: "yanliebing"
date: "2009-03-19T22:33:22Z"
tags: ["C", "C#", "C++", "quartz"]
slug: "ar"
draft: false
lastmod: "2009-03-19T22:35:33Z"
id: 351809
url: "https://yanliebing.iteye.com/blog/351809"
---

\[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之间的区别