[英]Is it possible to get a remote resource by using this API: ServletContext.getResourceAsStream()
Is it possible to get a remote resource by using this API: ServletContext.getResourceAsStream()
是否可以使用以下API获得远程资源:
ServletContext.getResourceAsStream()
For instance: ServletContext.getResourceAsStream("http://www.xxx.com/xx.txt");
例如:
ServletContext.getResourceAsStream("http://www.xxx.com/xx.txt");
Any idea? 任何想法?
Thanks. 谢谢。
getResourceAsStream is meant for retrieving resources within your web-app and (unless I've misunderstood and you're trying to request a URL within your own application) that isn't true here. getResourceAsStream旨在检索Web应用程序中的资源,并且(除非我误解了,除非您试图在自己的应用程序中请求URL),否则此处不正确。
You could just do something like: 您可以执行以下操作:
URL someUrl = new URL("http://some.link.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(someUrl.openStream()));
// do stuff with the input stream
in.close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.