The springboot project calls the method of a local jar package and needs the file path under the project resources. The file is stored under resources.
Trial and error process
1. Original code:
classloader.getsystemresource ("file name") , and the local operation is normal. However, an error null pointer is reported after the jar package is typed.
2. First modification:
Most people on the Internet say that they use
this. Getclass(). Getclassloader(). Getresource() , but they still can’t. the two principles are the same.
3. Second modification:
Another method is to use the file stream to obtain the file,
this. Getclass(). Getclassloader(). Getresourceasstream() , but this is to obtain the file directly. It needs to be the file path, but it can’t.
string filepath = system. Getproperty ("user. Dir") + "\ \ file name" , get the path of the jar package, add the file name to get the file address, but you need to put the file in the same file directory as the jar package.
system. Getproperty (“user. Dir”) + “\ double slash in file name” is in Windows environment. If it needs to be changed to “/” in Linux environment.
(at present, we haven’t found a way not to put the documents outside. There is a solution. I hope the bosses will give us their advice!)
- [solution] the resource file cannot be found in the jar package of Java
- IntelliJ idea sets the default working directory
- Golang gets the list of files under the folder
- Securityerror: error ᦇ 2148: SWF file (SWF file cannot access local resources)
- Boot / etc/ rc.local What about invalidity? resolvent
- HDFS and local file transfer and error reporting
- Class file for com.sun.beans.introspect.propertyinfo not found
- Solution to the problem of vs2017 error report unable to open source file
- Error: enoent: no such file or directory, stat ‘/ usr / local / var / www / /_ book/gitbook/git
- [solution] LD: warning: directory not found for option
- Install Java runtime JRE in Ubuntu 16.04
- cURL error 60: SSL certificate problem…
- pom.xml Depending on the error report, the problem of missing artifact XXX is solved
- Change the path in the user directory in Chinese Ubuntu to English
- Java – read all the files and folders in a certain directory and three methods to get the file name from the file path
- Solve cannot execute binary file: exec format error under Linux
- The solution to the problem that the method of interacting with database in the servlet class is invalid after the servlet submits 404, 500 refresh and becomes 404, and after connecting to the data pool
- Unitypackage failed to install or the express solution could not be installed
- How to solve SVN authorization failed error
- “Securityerror: error ා 2060: Security sandbox conflict: external interface caller XXX cannot access XXX”