• Post Reply Bookmark Topic Watch Topic
  • New Topic

Searching within a file  RSS feed

 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a simple file search for my JSP page which searches file names. However, I do not see any useful methods in java.io for temporarily openning a file to search for a string.
If this needs to be done individually by file, I can do that using my file name methods.. but I can't even think of a way to search within one file if I had the file name / path already in hand.
Does anyone have any suggestions? Thanks in advance!
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI... as inefficient as it may be.. I just wrote it up so I read every into a String and do an "fileContentsString.indexOf(searchString)"... thus, if it is -1 then it is not in the file.. if it is something else, it is in the file.
It does not take overly long either. I had it search through about 500 megs of mp3's for the letter 'q' and it returned 113 of them in about 90 seconds.
Now I will simply implement a way to exclude certain file extensions so the admin can select which to search within and which not. Figured I'd let you all know how I ended up doing it.
If anyone has a better suggestion, I'm all for it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!