• Post Reply Bookmark Topic Watch Topic
  • New Topic

pattern search  RSS feed

 
Rahul Gowda
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!