1/81
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
streams
represent a source that provides a sequence of bytes, such as a file, an IO device, an interprocess communication pipe, or a TCP/IP socket
output streams
input streams
these are the two types of streams
output streams
refers to a printer, remote server location, or a printer where the data is written
input streams
refers to a file or any source where the data can be read and assigned to the memory variables in the program
System.IO
in C#, the ___ namespace contains classes that allow to write and read files. it needs to be included in all programs that use streams
byte-oriented
all files are ___, meaning the data is written or read into the files in terms of bytes
FileStream
is a class that is used to create a byte-oriented stream attached to a file
FileStream(string filename, FileMode mode)
this is the code to be used for creating a FileStream object
mode
this parameter specifies how the file needs to be opened
FileMode.Create
file mode that creates a new output file, which will be overwritten if a file already exists
FileMode.CreateNew
file mode that creates a new output file that is not existing
FileMode.Open
file mode that opens an existing file
FileMode.OpenOrCreate
file mode that opens an existing file. if not, it creates a new one
FileMode.Truncate
file mode that opens an existing file and truncates the content that already exists
FileStream constructor
this is used to open a file that has access to read or write. it also contains methods to perform read and write operations
ReadByte()
this method reads a single byte from a file and returns as an integer value
Read()
this method reads the specified number of bytes from a file into an array
WriteByte()
method that writes the specified byte into the file
Write()
method that writes an array of bytes into the file
Flush()
this method instantly writes the data into the file
void Close()
this method closes the file, releasing the system resources that are allocated to it
position the file pointer inside the file at the required location
how can we access a file randomly?
file pointer
this determines the location of the next read/write operation to take place on the file
Seek()
this is the method used to relocate the file pointer in the file
Seek()
a method that allows setting the file position indicator of file pointer to the preferred location in the file
long Seek(long n, SeekOrigin Location)
this is the syntax for the Seek() method
Position property of the Stream class
the file pointer can get or set the position using which property?
CanRead
CanSeek
CanTimeout
CanWrite
length
ReadTimeout
WriteTimeout
aside from the Position property, these 7 properties are commonly used
bool CanRead
this returns true if the stream can be read
bool CanSeek
returns true if the stream supports position requests
bool CanWrite
returns true if the stream can be written
long length
contains the size of the stream
int ReadTimeout
indicates the time before a timeout occurs for read operations
int WriteTimeout
indicates the time before a timeout occurs for write operations
true
(T/F) to perform a character-based file for managing text files, use character streams to read and write into the file
StreamReader, StreamWriter
since, internally, each file consists of bytes, the FileStream is wrapped inside either a ___ or a ___. these classes automatically convert a byte stream into a character stream, and vice versa
StreamWriter
this writes characters to a stream and contains several constructors
StreamWriter(Stream stream)
this StreamWriter constructor is used to create a character-based output stream
StreamWriter(string fileName)
this StreamWriter constructor is used to open a file directly
Close()
this method of the StreamWriter class closes the file
Flush()
this method of the StreamWriter class instantly saves the file content from buffer to memory
Write()
this method of the StreamWriter class writes into the specified file using a File stream class
WriteLine()
this method of the StreamWriter class writes into a file, line by line
StreamReader
is a class that reads characters from a byte stream
StreamReader(Stream stream)
this StreamReader constructor is the name of an open stream such as IO devices or a file
StreamReader(string fileName)
this StreamReader constructor specifies the name of the file to open
Flush()
this method of the StreamReader class instantly saves the file content from buffer to memory
Close()
this method of the StreamReader class closes the file and is mandatory to this class
Read()
this method of the StreamReader class reads the content from the file stream
ReadLine()
this method of the StreamReader class reads the content line by line from the given file stream
ReadToEnd()
this method of the StreamReader class reads all characters from the current location until the end of the stream
Peek()
this method of the StreamReader class returns the value in the stream without moving the file pointer
Seek()
this method of the StreamReader class sets the file pointer at the desired position in a file
assemblies
are files that contain compiled code targeted at the .NET framework
physical packages meant for distributing code
assemblies are basically ___
true
(T/F) the .NET classes are actually contained in several assemblies
metadata
manifest
an assembly has two sections, which are?
metadata
includes info about the data types of the program that are being used
manifest
holds the info of the assembly, which consists of the name, version, number, and type of mapping information
.exe
.dll
an assembly has two file extensions, which are?
.exe
file extension for standalone applications
.dll
file extension for reusable components
C:\Windows\assembly
the .NET frameworks’ core assemblies location can be found where?
private assembly
simplest type of assembly that can only be used within a software package that is intended to be used
no, since the application can only see classes that are mentioned in its private assembly
are two private assemblies with the same class name a problem?
true
(T/F) private assembles do not require registry entries
shared assemblies
are libraries that other applications can commonly use
yes, since any other software can access a shared assembly
are security precautions necessary when using shared assemblies?
name collision
is a common problem in shared assembly wherein other classes or variables have the same name that matches with the other shared assembly
true
(T/F) a different form of the same assembly might overwrite the shared assembly, and the new version might be incompatible with the existing code
shared assemblies are given a strong, unique name based on the private key cryptography
what is done to avoid name collision in shared assemblies?
global assembly cache (GAC)
this enables several applications to share shared assembly
true
(T/F) in GAC, it is required to add the assembly to the special directory
true
(T/F) GAC is the centralized storage location for .NET assemblies`
create a project containing a class file
this is the first step in creating a shared assembly
it contains the methods and properties that you want other applications to access
what does the class file contain?
generate a strong name for the project
this is the second step in creating a shared assembly
ShareAssemblyMessageKeyFile
the strong name for a shared assembly is saved in a strong key filename, such as what?
true
(T/F) the strong key file is created named ShareAssemblyMessageKeyFile.snk and located at the solutions explorer
specify the key filename in the project by indicating its strong key file name in the AssemblyInfo.cs file
this is the third step in creating a shared assembly
compile the project to generate an assembly
this is the fourth and last step in creating a shared assembly
true
(T/F) in compiling the project to generate an assembly, the assembly is generated with the extension .dll