How to check end of file in c sharp


















Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid. Related Questions. Add autoincrement to end of filename if previous set of files exist. Api response truncate at the end. How to set expiry date in excel file. Vbscript compilation error : expected end of statement. How to set icon file for my application in linux. How to set the path to the file where the user saves the application?

Layout: fixed fluid. Web04 2. Strip HTML. Encode HTML. Paste as-is. Code block. For an example that uses StreamReader , see How to read a text file one line at a time. The files that are used in this example are created in the topic How to write to a text file. If you are not using the text files from How to write to a text file , replace the argument to ReadAllText and ReadAllLines with the appropriate path and file name on your computer.

Do not rely on the name of a file to determine the contents of the file. For example, the file myFile. Close ; Z. Dan Manges. I thought your original question was detecting the end of lines. If that's the case, then StreamReader has a ReadLine method which will help. Also, processing one character at a time and adding to an ArrayList of characters will not be very efficient regarding performance unless the input is small.

ToString ; Note: I didn't compile this, so the code might not compile directly. Hope this helps. Dan Manges wrote: Z. Dan Manges Ok, this is my problem. I have written the ascii character set to a file as strings followed by a series of other strings.

I am trying somehow to detect those characters so that I can format the file properly and read it back properly. I am having some trouble doing this as I can't find a good way to detect the ascii character.

The CTRL-Z sequence is trapped by the console and causes the input stream to close as if the "file had reached the end". Here is a link from msdn ReadLine method. Why not use something like TextReader. Read or TextReader. Not quite sure why you're asking this, since the answer you accepted to your previous question is the easiest way to do what you were asking there.

Are you just looking for alternate solutions? You should check the documentation for Console. In the Remarks it says:. The ReadKey method reads from the keyboard even if the standard input is redirected to a file with the SetIn method. ReadKey will block until you press a key on the keyboard. You can't use ReadKey to detect the end of redirected input.

If what you want is to get input from the console character by character, you can do something like this:. You can replace ConsoleKey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?



0コメント

  • 1000 / 1000