日志文章

2007年11月06日 09:20:00

读取jar中的配置文件

package com.apc.config;

import java.io.InputStream;
import java.net.URLDecoder;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class ReadJar
{
public static InputStream readConfigFile()
{
return readJarFile("com/apc/config/config.xml");
}
public static InputStream readJarFile(String packAndFileName)
{
String currentJarPath;
try
{
  currentJarPath   = URLDecoder.decode(ReadJar.class.getProtectionDomain().getCodeSource().getLocation().getFile(),   "UTF-8 ");
  JarFile currentJar =   new JarFile(currentJarPath);
  JarEntry dbEntry   =   currentJar.getJarEntry(packAndFileName);
  return currentJar.getInputStream(dbEntry);
}
catch (Exception e)
{
  return null;
  //e.printStackTrace();
}
}
}

Tags: 读取jar   配置文件  

类别: 无分类 |  评论(0) |  浏览(3949) |  收藏
发表评论