简体   繁体   中英

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()

For instance: 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.

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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