aspose file tools*
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
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: 19792
    
  20

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: 61769
    
  67

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java equivalent of PHP echo file_get_contents('http://www.example.com/') command?