title: Extract contents of a file using ContentHandler
body: <p>I'm trying to extract the contents of a txt file using ContentHandler, the below is my code and the contents of my file is </p>
  
  <pre><code>Sample content Sample contentSample contentSample contentSample contentSample contentSample contentSample contentSample contentSample contentSample contentSample contentSample
  </code></pre>
  
  <p>The below code is not showing the extracted contents, what am I missing here?</p>
  
  <pre><code>class Test { 
  private OutputStream outputstream;
  private ParseContext context;
  private Detector detector;
  private Parser parser;
  private Metadata metadata;
  private String extractedText;
  
  public Test() {
      context = new ParseContext();
      detector = new DefaultDetector();
      parser = new AutoDetectParser(detector);
      context.set(Parser.class, parser);
      outputstream = new ByteArrayOutputStream();
      metadata = new Metadata();
  }
  
  public void process(String filename) throws Exception {
      URL url;
      File file = new File(filename);
      if (file.isFile()) {
          url = file.toURI().toURL();
      } else {
          url = new URL(filename);
      }
      InputStream input = TikaInputStream.get(url, metadata);
      ContentHandler handler = new BodyContentHandler(outputstream);
      parser.parse(input, handler, metadata, context); 
      input.close();
  }
  
  public void getString() {
      //Get the text into a String object
      extractedText = outputstream.toString();
      //Do whatever you want with this String object.
      System.out.println("extracted text "+extractedText);
  }
  
  public static void main(String args[]) throws Exception {
      if (args.length == 1) {
          Test textExtractor = new Test();
          textExtractor.process("D:\\docs\\sample.txt");
          textExtractor.getString();
      } else { 
          throw new Exception();
      }
  }
  }
  </code></pre>