zoukankan      html  css  js  c++  java
  • 读取jar包内的文件内容

    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);
            }
        }
    }
  • 相关阅读:
    vue小结
    ES6中的super关键字
    es5和es6
    雅虎工程师提供的CSS初始化示例代码
    移动端rem用法总结
    批量压缩图片
    cordova
    cordova 添加插件时报错相关问题
    JS 数组中对象去重 reduce 用法
    中间件笔录
  • 原文地址:https://www.cnblogs.com/april-chen/p/10823886.html
Copyright © 2011-2022 走看看