In a project development process, the project root path to store a picture, to generate two-dimensional code called when the picture as a logo of two-dimensional codes, two-dimensional code can be generated properly in the windows environment, but deploy to production test after the two-dimensional code generating error environment, a FileNotFoundException JAR package resource path: / BOOT-INF / classes / ** / logo.png
Use of File IO stream generated during the two-dimensional code in the file read code is as follows:
Resource new new = a ClassPathResource the Resource (imgpath);
File File resource.getFile = ();
(! File.Exists ()) {IF
System.err.println ( "" + imgpath + "the file does not exist"!);
Return;
}
Image src = ImageIO.read (file);
when another interface call by reading the file when the file will use the jar: file // to read the server resources under the absolute path: jar: file // *** / logo .png
but this time logo.png file absolute path in linux server does not exist, you will not find a file error
====================== ================================================== =========================
be modified by inputStream stream file read the code as follows:
a ClassPathResource new new Resource = a ClassPathResource (imgpath);
the inputStream = Resource inputStream .getInputStream ();
Image src = ImageIO.read (inputStream);
when read from the stream will be removed by the file path in front of '/', in turn from lower relative path classpath start looking for, and then transferred into a stream treated
surface like this, particularly it relates to the underlying implementation
ClassPathResource, Class, and several jdk own class object, I look to you a limited level crossing gangster pointing ... Contact E-mail [email protected]