Search A Word In A File In Java

Search A Word In A File In Java

A simple technique that could well be considerably faster than indexOf() is to use a Scanner, with the method findWithinHorizon(). If you use a constructor that takes a File object, Scanner will internally make a FileChannel to read the file. And for matching it will end up using a for efficient string searchin Smart Kit River Crossing Game there. g. If you don't have access to JDK 5 but you can use JDK 1.4, then you can use java.util.regex and FileChannel yourself, but it will be more complex. Reading the file in chunks (e.g. Into a CharBuffer) is a good idea, but you need to consider that it's possible that the target string may be split between reads.

Search For A Word In A File