This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
i have a program that searches a document for a string, however i am having trouble trying to make the program able to search a folder of documents with sub-directories. i am using a fileDialog to pass the path of the document to the program, i want to be able to pass the a directoy path instead of a file path.
here is my code for passing the path to the program as a string:
Where exactly are you encountering problems? Does the code compile? When you run it what happens? How is the behavior different from what you expect?
Posting some code helps in explaining what you are trying to do, but you also need to answer the above questions to explain what actually happens. This will make it easier for us to answer your question.
my code compiles and it works how i expect it to work. my aim is to make a search engine program, at the moment my program searches a text file for a string and it will print out the line of occurrence. my next step is to allow my program to be able to search a folder of files, instead of just one file at a time. in the end i want to be able to rank each file by no. of string occurrences. but for now i am having trouble trying to implement the directory searching, i want it to be able to read a folder for it's contents, and then i can recursively call my searchfile method to search the document if the file at that instance is a document or if it is folder then to step into the sub-directory.
thankyou very much for your advice, after i have used the list method, how will access everything in the list, i.e. access the files/folders in the folder, i am sorry i am asking silly questions it's just that i am new to java and unfortunatrly struggling with it. if anyone can post an example of how i can do this, i would be very grateful.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joined: Mar 03, 2005
i am sorry about my name, i was not aware of this rule.... i have been trying to use the list method but i have been unsuccessful, i am not a java programmer and i am really struggling. if you could post an example of how i could do this, i will be very grateful.