dontknowmuch Posted August 1, 2007 Share Posted August 1, 2007 What would be the Java equivalent of the following PHP code? <?php$html = file_get_contents("http://www.google.com/index.html");echo "html: <br>" . nl2br(htmlentities($html));?> Link to comment Share on other sites More sharing options...
aspnetguy Posted August 2, 2007 Share Posted August 2, 2007 my java is very rusty and I have nowhere to test this out but I hope it at least points you in the right direction //equivalent of //$html = file_get_contents("http://www.google.com/index.html");String html = "";InputStream in = null;try { in = new BufferedInputStream (new FileInputStream(root + "/message.txt") ); int ch; while ((ch = in.read()) !=-1) { html += String.valueOf((char)ch); }}finally { if (in != null) in.close(); // very important}//echo "html: <br>" . nl2br(htmlentities($html));OutputStream out = response.getOutputStream();out.write(html); quite a bit to replace 2 php lines huh? Link to comment Share on other sites More sharing options...
spoonraker Posted August 20, 2007 Share Posted August 20, 2007 lol you slipped a dollar sign into your code toward the end...php > java Link to comment Share on other sites More sharing options...
aspnetguy Posted August 21, 2007 Share Posted August 21, 2007 the commented code (iwth the $) is the php eqivalent. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.