<p>Without the use of any external library, what is the simplest way to fetch a website's HTML content into a String?</p>

[{'answer_id': 31463, 'author': 'pek', 'author_id': 2644, 'author_profile': 'https://Stackoverflow.com/users/2644', 'pm_score': 7, 'selected': True, 'text': '<p>I\'m currently using this:</p>\n\n<pre><code>String content = null;\nURLConnection connection = null;\ntry {\n  connection =  new URL("http://www.google.com").openConnection();\n  Scanner scanner = new Scanner(connection.getInputStream());\n  scanner.useDelimiter("\\\\Z");\n  content = scanner.next();\n  scanner.close();\n}catch ( Exception ex ) {\n    ex.printStackTrace();\n}\nSystem.out.println(content);\n</code></pre>\n\n<p>But not sure if there\'s a better way.</p>\n'}, {'answer_id': 31471, 'author': 'Justin Bennett', 'author_id': 271, 'author_profile': 'https://Stackoverflow.com/users/271', 'pm_score': 2, 'selected': False, 'text': '<p>I just left <a href="https://stackoverflow.com/questions/31415/quick-way-to-find-a-value-in-html-java">this post in your other thread</a>, though what you have above might work as well.  I don\'t think either would be any easier than the other.  The Apache packages can be accessed by just using <code>import org.apache.commons.HttpClient</code> at the top of your code.</p>\n\n<p>Edit: Forgot the link ;)</p>\n'}, {'answer_id': 33986, 'author': 'Scott Bennett-McLeish', 'author_id': 1915, 'author_profile': 'https://Stackoverflow.com/users/1915', 'pm_score': 4, 'selected': False, 'text': '<p>This has worked well for me:</p>\n\n<pre><code>URL url = new URL(theURL);\nInputStream is = url.openStream();\nint ptr = 0;\nStringBuffer buffer = new StringBuffer();\nwhile ((ptr = is.read()) != -1) {\n    buffer.append((char)ptr);\n}\n</code></pre>\n\n<p>Not sure at to whether the other solution(s) provided are any more efficient or not.</p>\n'}, {'answer_id': 15219927, 'author': 'Scott Bennett-McLeish', 'author_id': 1915, 'author_profile': 'https://Stackoverflow.com/users/1915', 'pm_score': 1, 'selected': False, 'text': '<p>Whilst not vanilla-Java, I\'ll offer up a simpler solution. Use Groovy ;-)</p>\n\n<pre><code>String siteContent = new URL("http://www.google.com").text\n</code></pre>\n'}, {'answer_id': 51337796, 'author': 'dinesh kandpal', 'author_id': 4617050, 'author_profile': 'https://Stackoverflow.com/users/4617050', 'pm_score': -1, 'selected': False, 'text': '<p>Its not library but a tool named curl generally installed in most of the servers or you can easily install in ubuntu by </p>\n\n<pre><code>sudo apt install curl\n</code></pre>\n\n<p>Then fetch any html page and store it to your local file like an example </p>\n\n<pre><code>curl https://www.facebook.com/ &gt; fb.html\n</code></pre>\n\n<p>You will get the home page html.You can run it in your browser as well.</p>\n'}]
['https://Stackoverflow.com/questions/31462', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2644/']