简体   繁体   English

获取InputStream流式传输的文件的URL

[英]Get URL of the file streamed by InputStream

Models.jar contain the file cmudict, this jar file is added as class path to the project Models.jar包含文件cmudict,此jar文件作为类路径添加到项目中

InputStream in = this.getClass().getResourceAsStream("edu/cmu/sphinx/language/cmudict");

Above statement accesses the file cmudict Stream, but I want to print the complete URL of the file location, which also includes the location of Models.jar file. 上面的语句访问文件cmudict Stream,但是我想打印文件位置的完整URL,其中还包括Models.jar文件的位置。

How this can be achieved? 如何做到这一点?

This can be achieved very easy: 这可以很容易地实现:

URL resource = this.getClass().getResource();

Have a look at the API for more informations @see http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResource-java.lang.String- 看一下API以获得更多信息@see http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getResource-java.lang.String-

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM