It's not a secret anymore!*
The moose likes I/O and Streams and the fly likes searching a content in a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "searching a content in a file" Watch "searching a content in a file" New topic
Author

searching a content in a file

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi All,

suppose,there are(example D drive) some files which are having paragraph ...

if i give some word in search button..then i submit..now i want the file/files which is having the particular word...

how to do it?

please anyone can explain me

thanks & regards,
seetharaman
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18


This is an example of a recursive method - if the File is a directory, the same method is called with the new File. This will end if either a File is a file or a directory is empty; then the next File will be searched.

That leaves the implementation of the contains method. You'll have to read in each line and check for presence until the word is found. Look for BufferedReader and its readLine method for reading the File. You can use String's indexOf method to check if the word is present.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Apache lucene is a good text search engine if you need a thrid party library to do the search for you.


apigee, a better way to API!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: searching a content in a file
 
Similar Threads
Batch file to exit if server is not started
MS-Word Docs Access
how to open a msword document in IE using jsp
How to extract an xml file after matching content from a zip file using java
Print Word Document Programatically in Java