1/50
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Streams
source that provides bytes, files, I/O etc.
Input Streams
File where data can be read
Output Streams
where data can be written ex. printer
System.IO
namespace that contains classes, Allows read n’ write of files
File Stream
Class that is used to create byte-oriented stream
FileStream (string filename, FileMode mode)
Code Of File Stream
mode
parameter that specifies how files are opened
FileMode.Create
new output file, will be overwritten if the file already exists
FileMode.CreateNew
creates new output file, not existing
FileMode.Open
Opens an Existing file
FileMode.OpenOrCreate
Opens existing file, If not creates one
FileMode.Truncate
open existing file, Truncates the content
ReadByte
read a single byte from a file, returns an integer as a value
Read
reads specified number of bytes from a file into an array
WriteByte
writes specified byte into the file
Flush
instantly writes data into the file
void Close
closes the file, releases system resources allocated
Seek
used to relocate file pointer in the file
Seek()
allows setting the file position indicator to a preferred location
Seek() Syntax
Long Seek (long n, SeekOrigin Location)
bool CanRead
returns true, if stream can be read
bool CanSeek
returns true, if stream supports position request
bool CanTimeout
returns true, if stream can timeout
bool CanWrite
returns true, if stream can be written
long length
contains size of the stream
int ReadTimeout
indicates time before timeout occurs for read
int WriteTimeout
indicates time before timeout occurs for write
Stream Writer
write character to a stream
StreamWriter (Stream stream)
creates character-based output stream
StreamWriter (string fileName)
open file directly (sw)
Close()
closes the file , mandatory to StreamReader
write()
file stream class, writes into specified file
WriteLine()
line by line, write into file
StreamReader
class that read character from aa byte stream
StreamReader (Stream stream)
name of open stream ex. I/O
StreamReader (string fileName)
specifies the name of the file to open
Read () sr
from the file stream, Reads content
ReadLine() sr
from file stream, reads content line by line
ReadToEnd()
current location to end of stream, reads all characters
Peek()
returns value of stream without moving file pointer
Seek()
sets the file pointer at desired position
Assemblies
files that contain compiled code
.dll
reusable components
.exe
standalone applications
Metadata
includes information about data types
Manifest
holds information of the assembly
Private assembly
simplest, used only within software package, 2 not a problem, not require registry entries
Shared assembly
libraries that other application can use
Name collision
same name of class with other shared assemblies, might overwrite assembly, give a unique or strong name to avoid collision
GAC (Global assembly cache)
enables app to share assembly, required to add assembly to special directory, centralized location
Creating shared assembly
create project containing class file
strong name (strong.snk) located at solutions explorer
specify the key filename AssemblyInfo.cs
Compile project to create, extension will be .dll