1. This evening, a program was written that, based on a small spring boot site, found that using FileUtils.class.getResource (path) to get the resource files in the jar package was not successful and its path was strange
file:/users/lonecloud/documents/ideacode/git/export/target/export-0.0.1-snapshot.jar!/boot-inf/classes!/temp/ Temp.xls
After reviewing the data, and viewing the resource files in the jar package found! There are also classes! such words, Super strange. A compromise method was found in the back to solve the problem
public static File Getjarresourcefile (string path, String fileName) {//Get Container resource resolver resourcepatternresolver res Olver = new Pathmatchingresourcepatternresolver (); try {//Get all matching files resource[] resources = resolver.getresources (path + fileName); if (Resources.length > 1) {//get the file stream because in the jar file, you cannot get the file directly through the file resource path, but you can get the file stream in the jar package Inputstrea M stream = Resources[0].getinputstream (); if (logger.isinfoenabled ()) {logger.info ("read file stream [" + Stream + "]"); } String Targetfilepath = System.getproperty ("user.home") + File.separator + resources[0].getfilename (); if (logger.isinfoenabled ()) {Logger.info ("drop position [" + Targetfilepath + "]"); } File Ttffile = new file (Targetfilepath); Org.apache.commons.io.FileUtils.copyInputStreamToFile (stream, ttffile); return ttffile; }} catch (IOException e) {if (logger.iswarnenabled ()) {Logger.warn ("read file stream failed , writing to the local library failed! "+ e); }} throw new RuntimeException ("File not Found"); }
Springboot jar package run in Get resource file