package com.ewe.core.utils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 获取打包后jar的路径信息
* @author Administrator
* 2011-01-16 13:53:12
*/
public class JarTool {
private static final Logger LOGGER = LoggerFactory.getLogger(JarTool.class);
public static File getJarFile(String path,String filename) throws IOException{
InputStream source = JarTool.class.getClassLoader().getResourceAsStream(path+"/"+filename);
File destination = new File(filename);
FileUtils.copyInputStreamToFile(source, destination);
LOGGER.debug("Template path==>{}",destination.getAbsolutePath());
return destination;
}
}
我的文件在
eweHR.jar\BOOT-INF\classes\downloadfiles下
测试调用这个方法
getJarFile("downloadfiles","employees-T.xlsx")
默认会将jar包下的文件加载到根目录然后进行下载
file path==>E:\HR系统\eweHR\employees-T.xlsx