Tika解析文件Demo

阅读更多
package com.qin.testparser;

import java.io.File;
import java.io.FileInputStream;

import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MimeType;
import org.apache.tika.mime.MimeTypes;
import org.apache.tika.mime.MimeTypesFactory;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.parser.microsoft.OfficeParser;
import org.apache.tika.sax.BodyContentHandler;


/**
 * 使用Tika解析
 * 各种文件
 * 
 * 
 * @author qindongliang
 * 
 * 
 * ***/



public class ParseDoc {
	
	
	
	
	public static void main(String[] args)throws Exception {
		
		//FileInputStream f=new FileInputStream(new File("D:\\校讯通产品用户使用手册.doc"));
		//FileInputStream f=new FileInputStream(new File("E:\\tika\\tika in action.pdf"));
		 FileInputStream f=new FileInputStream(new File("D:\\345.jpg"));
		 Parser p= new AutoDetectParser();//自动获取一个合适的解析器类型  
		 //如果文件很大,那么这个值可以适当调大
		 BodyContentHandler hand= new BodyContentHandler(10000);
		 Metadata me=new  Metadata();		 
		 ParseContext pct=new ParseContext();
		// p.parse(f, hand ,new Metadata(), new ParseContext());
		 p.parse(f, hand ,me, pct);
		//打印读取的文本
		System.out.println(hand.toString());
		
		
	}

}

你可能感兴趣的:(java,tika)