Results 1 to 4 of 4
Thread: Scanner/BufferedReader?
- 02-20-2010, 02:26 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 92
- Rep Power
- 0
Scanner/BufferedReader?
Hi,
I am working on a project where I am recursing through a directory and checking all files/subdirectory files for a particular string. If the file contains the string I need to remove it.
Currently the way I handle this situation is by using Scanner on each file, taking the file in Line by Line and checking if the line.contains("mystring"). If it does, I remove it, and write the file, etc.
This seems to be very inefficent if a file does not contain mystring, as we still going through the file line by line.
With that being said, does anyone have any brighter ways to determine whether the file contains my string without having to parse through the file line by line to determine that?
Thanks.
- 02-20-2010, 03:27 AM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
Well, if you read the file into a String, you could then use indexOf("mystring") and that would tell you if the file contained that word, but you still have to read the file into a string and indexOf still looks at every word, you just wouldnt have to have a big for loop.
- 02-20-2010, 03:42 AM #3
Member
- Join Date
- Jan 2009
- Posts
- 92
- Rep Power
- 0
Yea that doesn't really sound like it would cut down on the efficency. How can I read an entire file into a single string curiously? Or what is the easiest way...
- 02-20-2010, 04:11 AM #4
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
Similar Threads
-
How to use BufferedReader?
By ProgramBeginner in forum New To JavaReplies: 4Last Post: 10-11-2011, 02:56 PM -
BufferedReader, need help!
By zacharyrod in forum New To JavaReplies: 10Last Post: 11-19-2009, 10:56 AM -
scanner vs. BufferedReader? printstream vs. FileWriter?
By diggitydoggz in forum New To JavaReplies: 1Last Post: 01-09-2009, 01:58 AM -
BufferedReader
By vidhya.sk in forum New To JavaReplies: 2Last Post: 09-18-2008, 01:57 PM -
BufferedReader empty
By Peter in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 06:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks