⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmldocparser.java

📁 一个LUCENE的示例,对初学者很有帮助
💻 JAVA
字号:
package sample.dw.paper.lucene.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;

import org.apache.lucene.demo.html.HTMLParser;

public class HTMLDocParser {
	private String htmlPath;
	
	private HTMLParser htmlParser;
	
	public HTMLDocParser(String htmlPath){
		this.htmlPath = htmlPath;
		initHtmlParser();
	}
	
	private void initHtmlParser(){
		InputStream inputStream = null;
		try {
			inputStream = new FileInputStream(htmlPath);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		if(null != inputStream){
			try {
				htmlParser = new HTMLParser(new InputStreamReader(inputStream, "utf-8"));
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
	}
	
	public String getTitle(){
		if(null != htmlParser){
			try {
				return htmlParser.getTitle();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return "";
	}
	
	public Reader getContent(){
	    if(null != htmlParser){
	    	try {
				return htmlParser.getReader();
			} catch (IOException e) {
				e.printStackTrace();
			}
	    }
	    return null;
	}
	
	public String getPath(){
		return this.htmlPath;		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -