Jsoup Example: print title from HTML file

Jsoup example: print title from html file tutorial for beginners and professionals, jsoup.parse() method, jsoup - java html parser providing facility to parse html document by java language with examples of printing title, links, images, form elements from url.

Jsoup Example: print title from HTML file

Jsoup Example: print title from HTML file

In this example, we will get the title of the HTML page from the HTML file. To do so, we are going to call Jsoup.parse() method that returns the reference of Document. The title() method of Document class returns the title of the HTML document.

  1. import java.io.File;  
  2. import java.io.IOException;  
  3. import org.jsoup.Jsoup;  
  4. import org.jsoup.nodes.Document;  
  5. public class JsoupPrintTitlefromHtml{  
  6.     public static void main( String[] args ) throws IOException{  
  7.                 Document doc = Jsoup.parse(new File("e:\\register.html"),"utf-8");  
  8.                 String title = doc.title();  
  9.                 System.out.println("title is: " + title);  
  10.     }  
  11.  

Output:

title is: Please Register