Reference Blog: http://blog.csdn.net/ciedecem/article/details/10382275
Problem:
The project needs to be loaded with JSON data from the file and placed in the Conf directory.
In the program
XXX.class.getResource ("App.json");
XXX.class.getClassLoader (). getResourceAsStream ("App.json")
Can not find the file, reported NullPointerException. The ClassLoader can only load files under the Classpath directory and cannot read files outside the jar file in either way.
Solution:
Reference Online Blog ... Knowing that the MAVEN project will package all the files in the Src/main/resources directory into a jar, the method above will work. So build the resources directory, found that it is indeed feasible!
Attached: class loader loading file mode
[Java]View PlainCopy
- <span style="WHITE-SPACE:PRE;" > </span>inputstream InputStream = emojiutil. Class.getclassloader (). getResourceAsStream ("Emoji.json");
- BufferedReader reader = new BufferedReader (new InputStreamReader (InputStream));
- StringBuilder STRSB = new StringBuilder ();
"Go" in a MAVEN project package configuration files into a jar package