You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: xml/System.IO/File.xml
+10-1Lines changed: 10 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4846,6 +4846,8 @@ The following example moves a file.
4846
4846
## Remarks
4847
4847
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.
4848
4848
4849
+
If the file ends with a newline sequence, no additional empty line is appended to the array. For example, a file containing `"line1\nline2\n"` produces the same two-element array (`["line1", "line2"]`) as a file containing `"line1\nline2"`.
4850
+
4849
4851
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.
4850
4852
4851
4853
@@ -4945,6 +4947,8 @@ The following example moves a file.
4945
4947
## Remarks
4946
4948
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.
4947
4949
4950
+
If the file ends with a newline sequence, no additional empty line is appended to the array. For example, a file containing `"line1\nline2\n"` produces the same two-element array (`["line1", "line2"]`) as a file containing `"line1\nline2"`.
4951
+
4948
4952
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.
4949
4953
4950
4954
@@ -5460,8 +5464,11 @@ You can use the <xref:System.IO.File.ReadLines*> method to do the following:
5460
5464
5461
5465
This method uses <xref:System.Text.Encoding.UTF8*> for the encoding value.
5462
5466
5467
+
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, or as the final sequence of characters in the file or stream if it ends without a newline sequence. If the file ends with a newline sequence, no additional empty line is returned. For example, a file containing `"line1\nline2\n"` produces the same two lines (`"line1"` and `"line2"`) as a file containing `"line1\nline2"`.
5468
+
5463
5469
## Examples
5464
-
The following example reads the lines of a file to find lines that contain specified strings.
5470
+
5471
+
The following example reads the lines of a file to find lines that contain specified strings.
@@ -5568,6 +5575,8 @@ You can use the <xref:System.IO.File.ReadLines*> method to do the following:
5568
5575
- Write the returned collection of lines to a file with the <xref:System.IO.File.WriteAllLines(System.String,System.Collections.Generic.IEnumerable{System.String},System.Text.Encoding)?displayProperty=nameWithType> method, or append them to an existing file with the <xref:System.IO.File.AppendAllLines(System.String,System.Collections.Generic.IEnumerable{System.String},System.Text.Encoding)?displayProperty=nameWithType> method.
5569
5576
- Create an immediately populated instance of a collection that takes an <xref:System.Collections.Generic.IEnumerable`1> collection of strings for its constructor, such as a <xref:System.Collections.Generic.IList`1> or a <xref:System.Collections.Generic.Queue`1>.
5570
5577
5578
+
A line is defined as a sequence of characters terminated by a carriage return ('\r'), a line feed ('\n'), a carriage return immediately followed by a line feed, or the end of the file or stream. If the file ends with a newline sequence, no additional empty line is returned. For example, a file containing `"line1\nline2\n"` produces the same two lines (`"line1"` and `"line2"`) as a file containing `"line1\nline2"`.
5579
+
5571
5580
]]></format>
5572
5581
</remarks>
5573
5582
<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>
Copy file name to clipboardExpand all lines: xml/System.IO/StreamReader.xml
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2520,6 +2520,8 @@ Following a call to <xref:System.IO.StreamReader.Close*>, any operations on the
2520
2520
## Remarks
2521
2521
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.
2522
2522
2523
+
If the stream ends with a newline sequence, no additional empty line is returned. For example, a stream containing `"line1\nline2\n"` produces the same two lines (`"line1"` and `"line2"`) as a stream containing `"line1\nline2"`.
2524
+
2523
2525
This method overrides <xref:System.IO.TextReader.ReadLine*?displayProperty=nameWithType>.
2524
2526
2525
2527
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*> 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*> method; however, this method slows performance and should be called only when absolutely necessary.
Copy file name to clipboardExpand all lines: xml/System.IO/StringReader.xml
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1058,6 +1058,8 @@ This implementation of `Close` calls the <xref:System.IO.StringReader.Dispose*>,
1058
1058
1059
1059
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`.
1060
1060
1061
+
If the string ends with a newline sequence, no additional empty line is returned. For example, the string `"line1\nline2\n"` produces the same two lines (`"line1"` and `"line2"`) as the string `"line1\nline2"`.
1062
+
1061
1063
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*> 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*> method and store the read characters in a preallocated buffer.
1062
1064
1063
1065
The following table lists examples of other typical or related I/O tasks.
@@ -1075,8 +1077,6 @@ This implementation of `Close` calls the <xref:System.IO.StringReader.Dispose*>,
1075
1077
|Read from a binary file.|[How to: Read and Write to a Newly Created Data File](/dotnet/standard/io/how-to-read-and-write-to-a-newly-created-data-file)|
1076
1078
|Write to a binary file.|[How to: Read and Write to a Newly Created Data File](/dotnet/standard/io/how-to-read-and-write-to-a-newly-created-data-file)|
1077
1079
1078
-
1079
-
1080
1080
## Examples
1081
1081
This code example is part of a larger example provided for the <xref:System.IO.StringReader> class.
Copy file name to clipboardExpand all lines: xml/System.IO/TextReader.xml
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1193,9 +1193,11 @@
1193
1193
<formattype="text/markdown"><![CDATA[
1194
1194
1195
1195
## Remarks
1196
-
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*?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.
1196
+
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*?displayProperty=nameWithType>, or the end of the reader's input. 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 has been reached.
1197
1197
1198
-
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*> 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.
1198
+
If the input ends with a newline sequence, no additional empty line is returned. For example, input containing `"line1\nline2\n"` produces the same two lines (`"line1"` and `"line2"`) as input containing `"line1\nline2"`.
1199
+
1200
+
If the method throws an <xref:System.OutOfMemoryException> exception, the reader's position in its underlying source 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*> buffer are discarded. Because the reader's position in the underlying source cannot be reset, 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 underlying source is unknown or the source does not support repositioning, the underlying source also needs to be reinitialized.
1199
1201
1200
1202
To avoid such a situation and produce robust code you should use the <xref:System.IO.TextReader.Read*> method and store the read characters in a preallocated buffer.
0 commit comments