JAVA读取jar包内部配置文件

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

package com.test;

import java.io.File;

import java.io.IOException;

import java.io.InputStream;

import .URL;

import java.util.Properties;

import java.util.jar.JarEntry;

import java.util.jar.JarFile;

public class Test9 {

public static void main(String[] args) throws IOException {

String jarName="/test_p.jar";//Jar包所在的位置

String fileName="config/application.properties";//文件在jar包里的路径

String resource = Test9.class.getResource(jarName).getFile();

File file = new File(resource);

JarFile jarFile = new JarFile(file);//读入jar文件

JarEntry entry = jarFile.getJarEntry(fileName);

InputStream input = jarFile.getInputStream(entry);//读入需要的文件

Properties props = new Properties();

props.load(input);

System.out.println(props.getProperty("Driver"));

jarFile.close();

}

}

相关文档
最新文档