In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to read files under resources when SpringBoot is deployed to Linux". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to read files under resources when SpringBoot is deployed to Linux.
Background
In normal business development, we usually put some fixed resource files under the resources folder, and get the files through the relative path when using them, which is a very simple function.
It seems that there are some small holes, such as the contents of the obtained files are garbled or the files cannot be read.
Read garbled code
This is very simple, ha. Specify in the maven plug-in that the files to be obtained later will not be compiled and will be typed into the package as is.
Org.apache.maven.plugins maven-resources-plugin sql xlsx xls reads files
This is a small pit, and it took an hour or two to find the problem. Despair
First list two absolutely not feasible, the main reason is that the re-development environment is no problem, running production can not pass
Method 1: File currentFolder = ResourceUtils.getFile ("classpath:excelTemplate/model.xls"); method 2: this.class.getResourceAsStream ("excelTemplate/model.xls")
Here are some possible ways to do it, but there are also some pitfalls. The pit was caused by an accident.
Method 1: Resource resource = new ClassPathResource ("excelTemplate/model.xls"); InputStream resourceAsStream = resource.getInputStream (); method 2: InputStream resourceAsStream = Thread.currentThread (). GetContextClassLoader (). GetResourceAsStream ("excelTemplate/model.xls")
These two methods are absolutely easy to use. Some friends may have reported an error when getting the file. If there is also an error, you can open it locally and try it now to see if the file is damaged.
With a picture and a truth, it definitely works.
Do not misunderstand that the program does run on Linux. In order to verify it, use the development tool Remote to debug remotely to facilitate screenshots.
At this point, I believe you have a deeper understanding of "how SpringBoot is deployed to Linux to read files under resources". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.