Read in the current contents of the java.net homepage : Scanner « File Input Output « Java






Read in the current contents of the java.net homepage

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

public class Main {
  public static void main(String[] args) throws Exception {

    URLConnection connection = new URL("http://java.net").openConnection();
    String text = new Scanner(connection.getInputStream()).useDelimiter("\\Z").next();

  }
}

   
  








Related examples in the same category

1.new Scanner(new BufferedReader(new FileReader("xanadu.txt")))
2.Split a string using Scanner class
3.Read file using Scanner class
4.Read user input from console using Scanner class
5.Scanning text with java.util.Scanner
6.Simplify the code in TextReader by using java.util.Scanner
7.Perform the conversions after parsing the String