Place the binary files in the resources directory in a normal Java project.
FileInputStream stream = new FileInputStream(getClass().getResource("/hoge.bin").getPath());
I wrote a program to call and use in such a form. It works fine in the IDE, so when I jar it with mvn and call it from the outside, I get a Not Found Exception.
If you unzip the jar, you'll definitely find hoge.bin
directly underneath. Other properties files in the same directory can be read. .. ..
Use Class # getResourceAsStream
instead of Class # getResource
.
InputStream stream = getClass().getResourceAsStream("/hoge.bin");
```
Subsequent programs may need to be modified, depending on how the InputStream is used.
Why?
Answer here: https://stackoverflow.com/a/941785
Files that have been jarted cannot be treated as individual files and must be referenced in the form of Stream.
I'd like to read a little more serious document, but I'm tired of being so shit, so this time.
## Why did you get so shit
It has a multi-project structure managed by maven, and the entry is project A, but resouces is that of project B, so it took time to identify the problem because I thought it was a mistake in my settings.
Recommended Posts