Get the content of a website (http) as a string
 
A very useful thing is to read the content of a website. That means, reading the sourcecode, the html code of that site. It can be of any type!
Here is a code example of a function, where you can enter the URL of the website, and it will return the content as a string, with the right breaks "\n"'s at the end of the line:
String getWebsiteContent(String websiteurl) {
  String document_content = "";
    try {
      URL url = new URL("http://google.com/");
      BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
      String str;
      while ((str = in.readLine()) != null)
        {
        document_content+="\n"+str;
        }
      in.close();
    }
  catch (MalformedURLException e) {}
  catch (IOException e) {}
  return document_content.substring(1);
  }


Don't forget the right imports!
import java.net.*;
import java.io.*;
 
admin / Dec 05, 2004
   
 
 
Login: 
Pass: 
 
 
     
     
2004 - 2019 / lookass.ch
makememad@lookass.ch