package com.chanpion.boot;

import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
 * @author April Chen
 * @date 2019/5/7 10:16
 */
public class JarFileReader {

    public void read(String path) throws IOException {
        URL url = ResourceUtils.getURL(path);
        File file = ResourceUtils.getFile(url);
        JarFile jarFile = new JarFile(file);
        JarEntry jarEntry = jarFile.getJarEntry("config.properties");
        Properties properties = new Properties();
        properties.load(jarFile.getInputStream(jarEntry));
        Enumeration<?> enumeration = properties.propertyNames();
        while (enumeration.hasMoreElements()) {
            String key = (String) enumeration.nextElement();
            String value = properties.getProperty(key);
            System.out.println(key + ": " + value);
        }
    }
}

 

相关文章:

  • 2021-06-01
  • 2021-05-18
  • 2022-12-23
  • 2021-05-29
  • 2021-05-18
  • 2021-11-13
  • 2021-09-25
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案