TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET StreamReader ReadToEnd Function

Use the StreamReader ReadToEnd Function to get the entire contents of a file into a string.
StreamReader, ReadToEnd. When reading files, we often need to get the entire file into a string. Many Functions in VB.NET can be used for this, including File.ReadAllText.
But with StreamReader ReadToEnd, we have another option. If we are already using StreamReader in the program, ReadToEnd is a particularly good choice.StreamReader
An example. We use the ReadToEnd method on a StreamReader, instance, so we should import System.IO. A Using-statement is the best way to use StreamReader.

And: We assign a String variable to the contents of the return value of ReadToEnd.

VB.NET program that uses StreamReader ReadToEnd Imports System.IO Module Module1 Sub Main() ' Wrap StreamReader in using block. Using streamReader As StreamReader = New StreamReader("C:\programs\file.txt") ' Get entire contents of file in string. Dim contents As String = streamReader.ReadToEnd() Console.WriteLine(contents) End Using End Sub End Module Output Thank you Friend
Notes. Some kinds of files, like CSV files, are best parsed with ReadLine. But for other kinds of files, like data files, ReadToEnd is a better choice.
A summary. In a recent project, ReadToEnd was valuable to me. It allowed the program to maintain more symmetry, a benefit over a Function like File.ReadAllText.File.ReadAllText
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf