Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,788 questions

10,874 answers

573 users

How to connect to and read a web page (URL) in Java

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial


7 views
asked Jun 30, 2017 by avibootz
edited Jun 30, 2017 by avibootz

1 Answer

0 votes
// java code that connect to and read a web page

package javaapplication1;

import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;

public class JavaApplication1 {
  
    public static void main(String[] args) {
        try
        {   
            URL website = new URL("http://www.collectivesolver.com/");
            URLConnection urlcon = website.openConnection();
            try (Scanner s = new Scanner(new InputStreamReader(urlcon.getInputStream()))) {
                int count = 0;
                while (s.hasNext()) {
                    System.out.println(s.next());
                    count++;
                }
                System.out.println("\ntokens: " + count);
            }
		}
		catch(Exception e) {
            System.out.println(e);
		}
    }
}


/*
run:
 
<!DOCTYPE
html>
<html>
<head>
<meta
charset="utf-8">
<title>Programming
&amp;
Software
Q&amp;A
|
CollectiveSolver</title>
<meta
name="description"
content="Programming
Questions
&amp;
Answers
in
Java,
C#,
C,
C++,
PHP,
MySQL,
Python,
JavaScript,
WinAPI,
Win32,
VB.NET,
SQL,
HTML5,
CSS3,
DataBase,
WordPress,
Dot.NET,
jQuery,
openGL,
DOM,
HTML,
CSS,
phpMyAdmin,
XAMPP,
Windows">
...

tokens: 5526

*/

 




answered Jun 30, 2017 by avibootz
...