C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet491/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   487   488   489   490   491   492   493   494   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Using a StreamReader

To create a character-based input stream, wrap a byte stream inside a 

StreamReader

.

StreamReader

 defines several constructors. A frequently used one is shown here:

StreamReader(Stream 



stream

)

Here, 



stream

 is the name of an open stream. This constructor throws an 



ArgumentNullException

if

stream

 is null. It throws 

ArgumentException

 if 


stream

 is not opened for input. Once created, 

a

StreamReader

 will automatically handle the conversion of bytes to characters.

The following program creates a simple disk-to-screen utility that reads a text file called 

“test.txt” and displays its contents on the screen. Thus, it is the complement of the key-to-disk 

utility shown in the previous section:

// A simple disk-to-screen utility that demonstrates a StreamReader.

using System;

using System.IO;

class DtoS {

  static void Main() {

    FileStream fin;

    string s;

    try {

      fin = new FileStream("test.txt", FileMode.Open);

    }

    catch(IOException exc) {



      Console.WriteLine("Error Opening File");

      Console.WriteLine(exc.Message);

      return ;

    }


    StreamReader fstr_in = new StreamReader(fin);

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   487   488   489   490   491   492   493   494   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish