From 2a1cd4fda8a4a8e649910d16b4dfa1ce7ae63543 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 12 May 2023 09:24:40 +0800 Subject: *misc --- .../docs/examples/prerequisites/streams/index.html | 453 +++++++++++++++++++++ 1 file changed, 453 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html (limited to 'ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html') diff --git a/ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html new file mode 100644 index 0000000..4168219 --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html @@ -0,0 +1,453 @@ + + + + + + + + + + + + + + + + + + + + + + + Streams | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Streams

+

When reading from a stream, if you need to go back to the beginning of the stream, you can use the Stream.Position property.

+
using (var stream = new File.OpenRead("path\\to\\file"))
+using (var reader = new StreamReader(stream))
+{	
+	// Read file content.
+	var content = reader.ReadToEnd();
+
+	// Go back to beginning of the stream.
+	stream.Position = 0;
+
+	// Read file content again.
+	content = reader.ReadToEnd();
+}
+
+

When writing to a file, you need to flush the writer for the data to be written to the stream. StreamWriter contains an internal buffer and the data is only written to the stream when the buffer is full, or Flush is called. Flush is automatically called when a using block exits.

+
using (var stream = new File.OpenWrite("path\\to\\file"))
+using (var writer = new StreamWriter(stream))
+{	
+	writer.WriteLine("Foo");
+	writer.Flush(); // Data is written from the writer buffer to the stream.
+} // Flush is also called here.
+
+ +
+
+
+
+ +

+ + + + + + + + + + + -- cgit v1.1-26-g67d0