954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Program to search text files in a folder

I'm given a project to develop program to search text files in a folder to find matches for a given text and list the containing files. I can't use Java built-in data structures. I have to use my own data structures with algorithms.
I thought of building a data-structure similar to a hash-map to contain the strings found in text files. But i cant think of an algorithm to search.

Thanks in advance for any help!.

kaushalya_uom
Newbie Poster
7 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

All you would need to do is loop thru all the files in the dir, then, in that loop, read thru each file until either you match the text or reach EOF.
What data structures would you need?

JamesCherrill
Posting Genius
Moderator
6,371 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

First I need to index the strings found in files to optimize the search.

kaushalya_uom
Newbie Poster
7 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

I got a way have a list of txt fils and folders, when we give the rootpath,here it is.

File listOffiles[];
rootFolder=new File(rootPath);
listOffiles=rootFolder.listFiles();//list to store

Here listOffiles will have the list of txt files & folders.
Then try to implement the rest.

Lahiru_UOM
Newbie Poster
1 post since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

Thank you!
I could finish it :-)

kaushalya_uom
Newbie Poster
7 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

But I want to optimize the algorithm.
I searched abooout some text compression algorithms to create codes for words, will it be effective instead of String.compare method?

kaushalya_uom
Newbie Poster
7 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

is any one there to help me? i need to know how a text folder is searched using java..
.

vaishnavicse
Newbie Poster
6 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 
is any one there to help me? i need to know how a text folder is searched using java.. .

There is no such thing as a text folder.
Also start a new thread with some code since in this thread there were some suggestions.
If those do not cover you, make your question a little bit more clear

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

Hi
im doing my final year in engineering in that we have to undergo a project. i am doing text search that is if we give a name like sachin and if that word present in that folder it has to display its content. how to do this?

vaishnavicse
Newbie Poster
6 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 
Hi im doing my final year in engineering in that we have to undergo a project. i am doing text search that is if we give a name like sachin and if that word present in that folder it has to display its content. how to do this?

Also start a new thread with some code since in this thread there were some suggestions.
If those do not cover you, make your question a little bit more clear

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

how to see your coding? i couldn't find...

vaishnavicse
Newbie Poster
6 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 
how to see your coding? i couldn't find...

This thread has a few suggestions. If you still have problems then START a new thread, withspecific questions followed with what you have done so far

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You