This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes java equivalent of PHP echo file_get_contents('http://www.example.com/') command? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "java equivalent of PHP echo file_get_contents( Watch "java equivalent of PHP echo file_get_contents( New topic
Author

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

nathan sullivan
Greenhorn

Joined: Dec 20, 2010
Posts: 3
What is the equivalent command of echo file_get_contents('http://www.example.com/') in java?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

If you're doing this in a JSP, then you'd use <c:import>.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Don't get me started about those stupid light bulbs.
 
subject: java equivalent of PHP echo file_get_contents('http://www.example.com/') command?
 
Similar Threads
printing
complete java desktop app GUI, to send email only inserting To,From,Subject,Message and press SEND
Application idea on File Directory System
JSP equivalent of the PHP file_get_contents()
Using import in wsdl