All pastes #23781 Raw Edit

Someone

public java v1 · immutable
#23781 ·published 2005-09-24 16:07 UTC
rendered paste body
import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.nio.ByteBuffer;import java.nio.channels.FileChannel;/* * $Header: StringMatch.java, 25/09/2005 01:30:07 luisantonioa Exp $ * * $Author: luisantonioa $ * $Date: 25/09/2005 01:30:07 $ * $Revision: 1 $ * $Log: StringMatch.java,v $ * Revision 1  25/09/2005 01:30:07  luisantonioa * Added copyright notice * *  * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html *//** * This class ... *  * @version $Revision: 1.2 $ $Date: 2004/06/27 08:12:59 $ */public class StringMatch{    public static void main(String[] args)    {        String filename = args[0];        String pattern = args[1];                new StringMatch().search(new File(filename), pattern);    }    /**     * @param file     * @param pattern     */    private void search(File file, String pattern)    {        try        {            BufferedReader br = new BufferedReader(new FileReader(file));            String line = br.readLine();            int pos = 0;            int lineNum = 1;            while (line != null)            {                //System.out.println(line);                pos = line.indexOf(pattern, 0);                while (pos >= 0)                {                    System.out.println("Found at Line "+lineNum+" pos "+(pos+1));                    pos = line.indexOf(pattern, pos+1);                }                line = br.readLine();                lineNum++;            }        }        catch (FileNotFoundException e)        {            // TODO Auto-generated catch block            e.printStackTrace();        }        catch (IOException e)        {            // TODO Auto-generated catch block            e.printStackTrace();        }    }}