title: How do I load a local html file into Jsoup?
body: <p>I can't seem to load in a local html file, using the Jsoup library. Or at the very least it doesn't seem to be recognising it. I hardcoded the exact html in the local file (as the var 'html') and when I switch to that instead of a file input the code works perfectly. But the file is read on both occasions.</p>
  
  <pre><code>import java.io.File;
  import org.jsoup.Jsoup;
  import org.jsoup.nodes.Document;
  import org.jsoup.nodes.Element;
  import org.jsoup.select.Elements;
  
  
  public class FileHtmlParser{
  
  public String input;
  
  
  //constructor
  public FileHtmlParser(String inputFile){input = inputFile;}
  
  
  //methods
  public FileHtmlParser execute(){
  
      File file = new File(input);
      System.out.println("The file can be read: " + file.canRead());
  
      String html = "&lt;html&gt;&lt;head&gt;&lt;title&gt;First parse&lt;/title&gt;&lt;meta&gt;106&lt;/meta&gt; &lt;meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /&gt;&lt;/head&gt;"
                + "&lt;body&gt;&lt;p&gt;Parsed HTML into a doc.&lt;/p&gt;" +
                "" +
                "&lt;div id=\"navbar\"&gt;this is the div&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;";
              Document doc = Jsoup.parseBodyFragment(input);
  
  
  
  
      Elements content = doc.getElementsByTag("div");
      if(content.hasText()){System.out.println("result is " + content.outerHtml());}
      else System.out.println("nothing!");
  
  
      return this;
  }
  
  }/*endOfClass*/
  </code></pre>
  
  <p><strong>Result when:<br>
  Document doc = Jsoup.parseBodyFragment(html)</strong></p>
  
  <pre><code>The file can be read: true
  result is &lt;div id="navbar"&gt;
  this is the div
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Result when:<br>
  Document doc = Jsoup.parseBodyFragment(input)</strong></p>
  
  <pre><code>The file can be read: true
  nothing!
  </code></pre>