First of all, its error is like this. As long as it encounters this error, the InputStream stream has not been closed after use, ()
: Cannot delete C:\Users\guo\AppData\Local\Temp\tomcat.8081.8076585834079724671\work\Tomcat\localhost\ROOT\upload_00daa733_afe5_4d51_a016_0ed308a7e006_00000000.tmp at (:431) ~[tomcat-embed-core-9.0.:9.0.79] at (:53) ~[tomcat-embed-core-9.0.:9.0.79] at (:134) ~[spring-web-5.3.:5.3.29] at (:1251) [spring-webmvc-5.3.:5.3.29] at (:1108) [spring-webmvc-5.3.:5.3.29] at (:965) [spring-webmvc-5.3.:5.3.29] at (:1006) [spring-webmvc-5.3.:5.3.29] at (:909) [spring-webmvc-5.3.:5.3.29] at (:555) [tomcat-embed-core-9.0.:4.] at (:883) [spring-webmvc-5.3.:5.3.29] at (:623) [tomcat-embed-core-9.0.:4.] at (:209) [tomcat-embed-core-9.0.:9.0.79] at (:153) [tomcat-embed-core-9.0.:9.0.79] at (:51) [tomcat-embed-websocket-9.0.:9.0.79] at (:178) [tomcat-embed-core-9.0.:9.0.79] at (:153) [tomcat-embed-core-9.0.:9.0.79] at (:100) [spring-web-5.3.:5.3.29] at (:117) [spring-web-5.3.:5.3.29] at (:178) [tomcat-embed-core-9.0.:9.0.79] at (:153) [tomcat-embed-core-9.0.:9.0.79] at (:93) [spring-web-5.3.:5.3.29] at (:117) [spring-web-5.3.:5.3.29] at (:178) [tomcat-embed-core-9.0.:9.0.79] at (:153) [tomcat-embed-core-9.0.:9.0.79] at (:201) [spring-web-5.3.:5.3.29] at (:117) [spring-web-5.3.:5.3.29] at (:178) [tomcat-embed-core-9.0.:9.0.79] at (:153) [tomcat-embed-core-9.0.:9.0.79] at (:167) [tomcat-embed-core-9.0.:9.0.79] at (:90) [tomcat-embed-core-9.0.:9.0.79] at (:481) [tomcat-embed-core-9.0.:9.0.79] at (:130) [tomcat-embed-core-9.0.:9.0.79] at (:93) [tomcat-embed-core-9.0.:9.0.79] at (:74) [tomcat-embed-core-9.0.:9.0.79] at (:343) [tomcat-embed-core-9.0.:9.0.79] at .http11.(:390) [tomcat-embed-core-9.0.:9.0.79] at (:63) [tomcat-embed-core-9.0.:9.0.79] at $(:926) [tomcat-embed-core-9.0.:9.0.79] at $(:1790) [tomcat-embed-core-9.0.:9.0.79] at (:52) [tomcat-embed-core-9.0.:9.0.79] at (:1191) [tomcat-embed-core-9.0.:9.0.79] at $(:659) [tomcat-embed-core-9.0.:9.0.79] at $(:61) [tomcat-embed-core-9.0.:9.0.79] at (:750) [na:1.8.0_322] Caused by: : Cannot delete C:\Users\guo\AppData\Local\Temp\tomcat.8081.8076585834079724671\work\Tomcat\localhost\ROOT\upload_00daa733_afe5_4d51_a016_0ed308a7e006_00000000.tmp ... 44 common frames omitted
My code was like this at that time. I thought it would be enough to directly assign the stream. I forgot that this is the address. Once the value is reassigned, it points to the new input stream. No one pointed to the original stream. JVM will be cleared regularly. But I didn't turn off the stream, so I kept reporting the bug on it. How to say it, keep a little brain when writing code.
public static InputStream pictureCompression(InputStream inputStream,String suffix, float scale) throws IOException { File tempFile = ("temp", suffix); try { (inputStream) .scale(scale) .toFile(tempFile); inputStream = new FileInputStream(tempFile); } catch (IOException e) { ("[Image compression failed]"); } finally { (); // Delete temporary files } return inputStream; }
Just turn it off like this
public static InputStream pictureCompression(InputStream inputStream,String suffix, float scale) throws IOException { File tempFile = ("temp", suffix); try { (inputStream) .scale(scale) .toFile(tempFile); (); inputStream = new FileInputStream(tempFile); } catch (IOException e) { ("[Image compression failed]"); } finally { (); // Delete temporary files } return inputStream; }
This is the article about the issue of: Cannot delete C:\Users\guo\AppData\Local\Temp\tomcat.8081. This is all about this. For more related content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!