I have a request from my user to list of the files from the folders
which has got the string he is searching for. How do I implement the
unix command grep in JAVA. or are there any methods/interfaces in java
that can scan file(s) in a given folder & do the same functionality?
Regards,
P
You have the machinery of java.io.File to locate the
files in a directory, and other machinery in java.io to
open them and read their contents. The java.util.regex
package provides classes and methods that should be helpful
in detecting the presence of the desired strings -- or if
they're really just strings and not regular expressions,
you might simply use the indexOf(String) method of String.
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
How about:
http://www.ebi.ac.uk/Rebholz-srv/whatizit/monq-doc/monq/programs/Grep.html
It has a main() to run it from the command line,
but all the functionality is encapsulated in
a class too. The concept of `line' is, however,
replaced by the concept of `region of interest',
which makes it a nice tool for XML grepping.
Harald.