Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java equivalent of PHP echo file_get_contents('http://www.example.com/') command?

 
nathan sullivan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the equivalent command of echo file_get_contents('http://www.example.com/') in java?
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no one-method equivalent. You can do it with a few methods though:
To increase performance you can use a BufferedInputStream or BufferedReader in line 2 of the above code, and possibly create the StringWriter with the content-length of the URL's URLConnection. You would need to change lines 2-3 into this:
You would need to check if length is not -1 though, or creating the StringWriter would fail.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're doing this in a JSP, then you'd use <c:import>.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic