FindFile.java Source code

Java tutorial

Introduction

Here is the source code for FindFile.java

Source

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author mtgb
 */
public class FindFile {

    File f = null;
    public String srcword;

    public FindFile() {

    }

    public void search(String gUrl) {
        try {
            FileInputStream fis = new FileInputStream(gUrl);
            XWPFDocument docx = new XWPFDocument(OPCPackage.open(fis));
            List<XWPFParagraph> parag = docx.getParagraphs();
            int cntrl = 0;
            for (XWPFParagraph paraglist : parag) {
                String gelen = paraglist.getText().trim();
                String[] temp = gelen.split(" ");
                for (String temp2 : temp) {
                    if (temp2.contains(srcword)) {
                        cntrl++;
                        System.out.println(cntrl + "----->" + temp2);
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}