Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions xml/System.IO/File.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4846,6 +4846,8 @@ The following example moves a file.
## Remarks
This method opens a file, reads each line of the file, then adds each line as an element of a string array. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating carriage return and/or line feed.

If the file ends with a newline sequence, no additional empty line is appended to the array. For example, a file containing `"foo\nbar\n"` produces the same two-element array (`["foo", "bar"]`) as a file containing `"foo\nbar"`.
Comment thread
gewarren marked this conversation as resolved.
Outdated

This method attempts to automatically detect the encoding of a file based on the presence of byte order marks. Encoding formats UTF-8 and UTF-32 (both big-endian and little-endian) can be detected.


Expand Down Expand Up @@ -4945,6 +4947,8 @@ The following example moves a file.
## Remarks
This method opens a file, reads each line of the file, and then adds each line as an element of a string array. It then closes the file. A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. The resulting string does not contain the terminating carriage return and/or line feed.

If the file ends with a newline sequence, no additional empty line is appended to the array. For example, a file containing `"foo\nbar\n"` produces the same two-element array (`["foo", "bar"]`) as a file containing `"foo\nbar"`.

This method attempts to automatically detect the encoding of a file based on the presence of byte order marks. Encoding formats UTF-8 and UTF-32 (both big-endian and little-endian) can be detected.


Expand Down Expand Up @@ -5463,6 +5467,8 @@ The following example moves a file.

This method uses <xref:System.Text.Encoding.UTF8%2A> for the encoding value.

A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. If the file ends with a newline sequence, no additional empty line is returned. For example, a file containing `"foo\nbar\n"` produces the same two lines (`"foo"` and `"bar"`) as a file containing `"foo\nbar"`.



## Examples
Expand Down Expand Up @@ -5576,6 +5582,8 @@ The following example moves a file.

- Create an immediately populated instance of a collection that takes an <xref:System.Collections.Generic.IEnumerable%601> collection of strings for its constructor, such as a <xref:System.Collections.Generic.IList%601> or a <xref:System.Collections.Generic.Queue%601>.

A line is defined as a sequence of characters followed by a carriage return ('\r'), a line feed ('\n'), or a carriage return immediately followed by a line feed. If the file ends with a newline sequence, no additional empty line is returned. For example, a file containing `"foo\nbar\n"` produces the same two lines (`"foo"` and `"bar"`) as a file containing `"foo\nbar"`.

]]></format>
</remarks>
<exception cref="T:System.ArgumentException">.NET Framework and .NET Core versions older than 2.1: <paramref name="path" /> is a zero-length string, contains only white space, or contains one or more invalid characters as defined by the <see cref="M:System.IO.Path.GetInvalidPathChars" /> method.</exception>
Expand Down
2 changes: 2 additions & 0 deletions xml/System.IO/StreamReader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2520,6 +2520,8 @@ Following a call to <xref:System.IO.StreamReader.Close%2A>, any operations on th
## Remarks
A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r"), or a carriage return immediately followed by a line feed ("\r\n"). The string that is returned does not contain the terminating carriage return or line feed. The returned value is `null` if the end of the input stream is reached.

If the stream ends with a newline sequence, no additional empty line is returned. For example, a stream containing `"foo\nbar\n"` produces the same two lines (`"foo"` and `"bar"`) as a stream containing `"foo\nbar"`.

This method overrides <xref:System.IO.TextReader.ReadLine%2A?displayProperty=nameWithType>.

If the current method throws an <xref:System.OutOfMemoryException>, the reader's position in the underlying <xref:System.IO.Stream> object is advanced by the number of characters the method was able to read, but the characters already read into the internal <xref:System.IO.StreamReader.ReadLine%2A> buffer are discarded. If you manipulate the position of the underlying stream after reading data into the buffer, the position of the underlying stream might not match the position of the internal buffer. To reset the internal buffer, call the <xref:System.IO.StreamReader.DiscardBufferedData%2A> method; however, this method slows performance and should be called only when absolutely necessary.
Expand Down
2 changes: 2 additions & 0 deletions xml/System.IO/StringReader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ This implementation of `Close` calls the <xref:System.IO.StringReader.Dispose%2A

A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r"), a carriage return immediately followed by a line feed ("\r\n"), or the end-of-stream marker. The string that is returned does not contain the terminating carriage return or line feed. The returned value is `null` if the end-of-stream marker has been reached. That is to say, if there is nothing between the last line read and the end-of-stream marker, the method returns `null`.

If the string ends with a newline sequence, no additional empty line is returned. For example, the string `"foo\nbar\n"` produces the same two lines (`"foo"` and `"bar"`) as the string `"foo\nbar"`.

If the current method throws an <xref:System.OutOfMemoryException>, the reader's position in the underlying string is advanced by the number of characters the method was able to read, but the characters already read into the internal <xref:System.IO.StringReader.ReadLine%2A> buffer are discarded. Because the position of the reader in the string cannot be changed, the characters already read are unrecoverable, and can be accessed only by reinitializing the <xref:System.IO.StringReader>. To avoid such a situation, use the <xref:System.IO.StringReader.Read%2A> method and store the read characters in a preallocated buffer.

The following table lists examples of other typical or related I/O tasks.
Expand Down
2 changes: 2 additions & 0 deletions xml/System.IO/TextReader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@
## Remarks
A line is defined as a sequence of characters followed by a carriage return (0x000d), a line feed (0x000a), a carriage return followed by a line feed, <xref:System.Environment.NewLine%2A?displayProperty=nameWithType>, or the end-of-stream marker. The string that is returned does not contain the terminating carriage return or line feed. The return value is `null` if the end of the input stream has been reached.

If the stream ends with a newline sequence, no additional empty line is returned. For example, a stream containing `"foo\nbar\n"` produces the same two lines (`"foo"` and `"bar"`) as a stream containing `"foo\nbar"`.

If the method throws an <xref:System.OutOfMemoryException> exception, the reader's position in the underlying <xref:System.IO.Stream> is advanced by the number of characters the method was able to read, but the characters that were already read into the internal <xref:System.IO.TextReader.ReadLine%2A> buffer are discarded. Because the position of the reader in the stream cannot be changed, the characters that were already read are unrecoverable and can be accessed only by reinitializing the <xref:System.IO.TextReader> object. If the initial position within the stream is unknown or the stream does not support seeking, the underlying <xref:System.IO.Stream> also needs to be reinitialized.

To avoid such a situation and produce robust code you should use the <xref:System.IO.TextReader.Read%2A> method and store the read characters in a preallocated buffer.
Expand Down