I'm using C# (.Net 2.0), and I have a fairly large text file (~1600 lines on average) that I need to check periodically to make sure a certain line of text is there.
What is the most efficient way of doing this? Do I really have to load the entire file into memory each time?
Is there a file-content-search api of some sort that I could use?
Thanks for any help/advice.
Use ReadAllLines() method to read all the lines one by one in a file.
You can call the shell command file -i ${filename} from Java, and check the output to see if it contains something like charset=binary . If it does, then it is binary file. Otherwise it is text based file.
The contains() method checks whether a string contains a sequence of characters. Returns true if the characters exist and false if not.
Method 1: fileobject.readlines() A file object can be created in Python and then readlines() method can be invoked on this object to read lines into a stream.
Well, you can always use the FileSystemWatcher to give you an event when the file has changed, that way you only scan the file on demand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With