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

📄 lucenepptdocument.java

📁 lucene环境下ppt转txt的源代码,这个代码应该对搜索引擎有一定作用
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package lucenesearch;import java.io.*;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;import org.apache.poi.hslf.HSLFSlideShow;import org.apache.poi.hslf.model.TextRun;import org.apache.poi.hslf.model.Slide;import org.apache.poi.hslf.usermodel.SlideShow;/** * * @author BileiZhu */public class LucenePPTDocument {    public static Document getDocument(File doc) {        String docPath = doc.getAbsolutePath();        String title = doc.getName();        FileInputStream inputStream = null;        Reader contents = null;        Document document = new Document();        try {            inputStream = new FileInputStream(doc);        } catch (FileNotFoundException e) {            System.out.println(e);        }        StringBuffer sBuff = new StringBuffer("");        try {            SlideShow ss = new SlideShow(new HSLFSlideShow(inputStream));            Slide[] slides = ss.getSlides();            for (int i = 0; i < slides.length; i++) {                TextRun[] t = slides[i].getTextRuns();                for (int j = 0; j < t.length; j++) {                    sBuff.append(t[j].getText());                }            }        } catch (Exception e) {            System.out.println(e);        }        contents = new StringReader(sBuff.toString());        document.add(new Field("path", docPath, Field.Store.YES, Field.Index.NO));        document.add(new Field("title", title, Field.Store.YES, Field.Index.TOKENIZED));        document.add(new Field("contents", contents));        document.add(new Field("information", docPath + Long.toString(doc.lastModified()), Field.Store.YES, Field.Index.UN_TOKENIZED));        return document;    }}

⌨️ 快捷键说明

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