C# 0 The Complete Reference


FileStream  class.  FileStream



Download 4,07 Mb.
Pdf ko'rish
bet483/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   479   480   481   482   483   484   485   486   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

FileStream

 class. 


FileStream

 is derived from 



Stream

 and contains all of 



Stream

’s functionality.

Remember, the stream classes, including 

FileStream

, are defined in 



System.IO

. Thus, 


you will usually include

using System.IO;

near the top of any program that uses them.

Opening and Closing a File

To create a byte stream linked to a file, create a 



FileStream

object.


FileStream

 defines 

several constructors. Perhaps its most commonly used is the one shown here:

FileStream(string 



fi lename

, FileMode 



mode

)

Here, 



filename

 specifies the name of the file to open, which can include a full path specification. 

The

mode

 parameter specifies how the file will be opened. It must be one of the values 

defined by the 

FileMode

 enumeration. These values are shown in Table 14-4. In general

this constructor opens a file for read/write access. The exception is when the file is opened 

using


FileMode.Append

. In this case, the file is write-only.

If a failure occurs when attempting to open the file, an exception will be thrown. If the file 

cannot be opened because it does not exist, 



FileNotFoundException

 will be thrown. If the 

file cannot be opened because of some type of I/O error, 

IOException

 will be thrown. Other

possible exceptions are 

ArgumentNullException

 (the filename is null), 



ArgumentException

(the filename is invalid), 



ArgumentOutOfRangeException

 (the mode is invalid), 



SecurityException

 (user does not have access rights), 



PathTooLongException

 (the filename/

path is too long), 

NotSupportedException

 (the filename specifies an unsupported device), 

and

DirectoryNotFoundException

(specified directory is invalid).

Value

Description



FileMode.Append

Output is appended to the end of file.

FileMode.Create

Creates a new output file. Any preexisting file by the same name 

will be destroyed.

FileMode.CreateNew

Creates a new output file. The file must not already exist.

FileMode.Open

Opens a preexisting file.

FileMode.OpenOrCreate

Opens a file if it exists, or creates the file if it does not already 

exist.


FileMode.Truncate

Opens a preexisting file, but reduces its length to zero.

T

ABLE


 14-4 

The


FileMode

 Values


www.freepdf-books.com


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   479   480   481   482   483   484   485   486   ...   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