read_file_stream
Differences
This shows you the differences between two versions of the page.
Last revisionBoth sides next revision | |||
read_file_stream [2018/01/27 20:14] – created wolfgangriedmann | read_file_stream [2018/01/27 20:43] – wolfgangriedmann | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Read a file using a stream ====== | ====== Read a file using a stream ====== | ||
+ | |||
+ | If you need to read a larger file and process it during the read, you should use a stream for it. | ||
+ | This is largely used when reading or writing in the network using internet protocols. | ||
+ | |||
+ | This is a sample how to read a file using a stream: | ||
+ | < | ||
+ | using System.Text | ||
+ | |||
+ | function ReadFileStream( cFileName as string ) as void | ||
+ | local oFileStream as FileStream | ||
+ | local aBytes as byte[] | ||
+ | local nOffset as int | ||
+ | local nRead as int | ||
+ | local nBufLen as int | ||
+ | local cBuffer as string | ||
+ | |||
+ | nOffset := 0 | ||
+ | nBufLen := 10 | ||
+ | cBuffer := "" | ||
+ | aBytes := byte[]{ 10 } | ||
+ | oFileStream := FileStream{ cFileName, FileMode.Open, | ||
+ | while ( nRead := oFileStream: | ||
+ | cBuffer := cBuffer + System.Text.Encoding.UTF32: | ||
+ | nOffset := nOffset + nRead | ||
+ | end | ||
+ | System.Console.WriteLine( "Read with stream:" | ||
+ | |||
+ | return</ | ||
+ | |||
+ | You will find more information about the [[https:// | ||
+ | Please pay attention to the correct [[encodings|Encoding]]! | ||
read_file_stream.txt · Last modified: 2018/01/27 20:44 by wolfgangriedmann