What’s the fastest way to read a text file line-by-line?

I want to read a text file line by line. I wanted to know if I’m doing it as efficiently as possible within the .NET C# scope of things. This is what I’m trying so far: var filestream = new System.IO.FileStream(textFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite); var file = new System.IO.StreamReader(filestream, System.Text.Encoding.UTF8, true, 128); while ((lineOfText = … Read more

How can you find and replace text in a file using the Windows command-line environment?

I am writing a batch file script using Windows command-line environment and want to change each occurrence of some text in a file (ex. “FOO”) with another (ex. “BAR”). What is the simplest way to do that? Any built in functions? 30 s 30 A lot of the answers here helped point me in the … Read more

How do I save a String to a text file using Java?

In Java, I have text from a text field in a String variable called “text”. How can I save the contents of the “text” variable to a file? 23 s 23 If you’re simply outputting text, rather than any binary data, the following will work: PrintWriter out = new PrintWriter(“filename.txt”); Then, write your String to … Read more