tags: getResourceAsStream() Javaweb path
Take the example tomcat comes to do the project examples:
// "/" with respect to E: \ app \ apache-tomcat-8.5.31 \ webapps \ examples
session.getServletContext().getResourceAsStream("/");
// relative to the E: \ app \ apache-tomcat-8.5.31 \ webapps \ examples \ WEB-INF \ classes
this.getClass().getResourceAsStream("/");
// same:. This.getClass () getResourceAsStream ( "/") ;, but do not write "/"
this.getClass().getClassLoader().getResourceAsStream("");
From the tested code can be seen
1. session.getServletContext().getResourceAsStream("/"); Equivalent to the current project directory compiled, "/" represents the root directory of the current project;
2. this.getClass().getResourceAsStream("/");Equivalent WEB-INF \ classes, "/" on behalf of classes directory (compiled src directory) under the current project;
3. this.getClass().getClassLoader().getResourceAsStream("");And this.getClass () getResourceAsStream ( "/");.. The same directory beginning, the difference is not to write "/", in fact getClass () getResourceAsStream ( "/") is called a source ingetClassLoader()Method, write without any increase in forward slashes.
To solve this problem is very simple: windows version press the shortcut key alt + shift + ctrl + s mac:command + ; Enter the module configuration, select the module you are using, click sources, crea...
The method uses a ClassLoader getResource utf-8 encoded path information, when the pathThe presence of Chinese and space, he will convert these characters, so that, more often than not get what we wan...
GetresourceASSTREAM in Java Return to NULL problem processing: The main reason for this problem is the setting of the source: In our commonly used IDEA, the input stream returned with GetResourceASS...
ClassLoader, a small-name class loader, sounds so tall, the explanation of the online god is esoteric, just getting started, it is difficult to understand. My understanding of it is to load some files...
Directory Structure: debug finds that in is empty, the code is not wrong, only the content of the db.properties file is not read The first feeling is that there may be a problem with the resources fil...
Directly on the map, to facilitate comparison I do not understand even a path in which the above configuration, oh, on the map, even though some of my colleagues in the eyes of eclise have become anti...
[size=large][b]Class's getResourceAsStream(String path)[/b][/size] 1) Relative and absolute paths can be used, and absolute paths start with '/', such as 2) The relative path is the file under the cur...
Foreword In java there are some differences in resource acquisition path, commonly used getResource and getResourceAsStream 1.Class.getResource(String path) path not to '/' a...
This is a very basic question, here are some examples to help you quickly understand and remember the problem...