Alex Rivera | Logout

InputStream from a URL

Asked 2011-08-03T19:48:09.173
148

How do I get an InputStream from a URL?

for example, I want to take the file at the url wwww.somewebsite.com/a.txt and read it as an InputStream in Java, through a servlet.

I've tried

InputStream is = new FileInputStream("wwww.somewebsite.com/a.txt");

but what I got was an error:

java.io.FileNotFoundException
Edit
Report

1 Answer

23

Try:

final InputStream is = new URL("http://wwww.somewebsite.com/a.txt").openStream();
answered 2011-08-03T19:51:31.657

Your Answer