[英]this.getClass().getClassLoader().getResourceAsStream always returning null
While reading a file in a web application with 在使用以下命令在Web应用程序中读取文件时
this.getClass().getClassLoader().getResourceAsStream(../abc.txt)
is always returning null. 始终返回null。 Can anyone please provide details where should I put abc.txt in order to read.
任何人都可以提供详细信息,以便将abc.txt放在哪里阅读。 And any article on getResourceAsStream will be helpful.
而且有关getResourceAsStream的任何文章都将有所帮助。 I have searched a lot but did not get any relevant information.
我进行了很多搜索,但未获得任何相关信息。
Please provide your valuable suggestions. 请提供您宝贵的建议。 Thanks.
谢谢。
If your abc.txt
is in classpath
and in different package like com/test/oops/testpaper/abc.txt
. 如果您的
abc.txt
位于classpath
并且位于com/test/oops/testpaper/abc.txt
classpath
的其他包中。
Then read it like below. 然后像下面这样阅读。
InputStream io=this.getClass().getClassLoader().getResourceAsStream("com/test/oops/testpaper/abc.txt");
For detail please go through java doc . 有关详细信息,请阅读java doc 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.