天天看点

Spring boot 读取jar包中resources下的文件

package com.jiankunking.elasticsearch.extension.util;

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author jiankunking.
 * @date:2018/10/12 18:20
 * @description:
 */
public class ResourceRenderer {
    public static InputStream resourceLoader(String fileFullPath) throws IOException {
        ResourceLoader resourceLoader = new DefaultResourceLoader();
        return resourceLoader.getResource(fileFullPath).getInputStream();
    }
}
      

使用:

String fileName = "classpath:/k8s/kubectl.kubeconfig";
InputStream inputStream = ResourceRenderer.resourceLoader(fileName);      

资源目录:

Spring boot 读取jar包中resources下的文件

个人微信公众号:

继续阅读