IntelliJ Java IDE
The moose likes Java in General and the fly likes pattern search Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "pattern search" Watch "pattern search" New topic
Author

pattern search

Rahul Gowda
Greenhorn

Joined: Feb 11, 2012
Posts: 1
Hi All,

I had a question on pattern matching. Lets say I have a huge text file (around 100 MB). I know that I can implement KMP algorithm to do a pattern search. But I dont want to use a simple string to read all contents of the file and then do a search on it. Is there a better data structure to store the contents of the text file and then do a pattern search?
Please advice.

Thanks, Rahul
Viktor Kubinec
Greenhorn

Joined: Jan 28, 2012
Posts: 28
Try to use java.util.Scanner

it provides you a constructor with InputStream as an argument and it provides also methods for pattern search. Maybe this can help you.
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18370

Unless your pattern contains line breaks you only need to check the current line. In general, if the pattern contains X line breaks then you only need to check the last X+1 lines.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
 
subject: pattern search
 
Threads others viewed
How can I display the contents of a file
how to open .class file
Excel Sheets
How to insert text into an existing(really big) file
Finding the position in a File
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture