TIKA Document Type Detection


TIKA facade class detect() method is used to detect the document type based on the input file.

Example

In this program, we can detect file type based on the input file.

import java.io.File;
import org.apache.tika.Tika;
public class TikaTypeDetection {

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

      //Suppose hello.txt is in your current directory
      File file = new File("hello.txt");//

      //Instante tika facade class
      Tika tika = new Tika();

      //detect file type using detect method
      String filetype = tika.detect(file);
      System.out.println(filetype);
   }
}

Output


text/plain

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s