PREFINALS | Streams | Event-Driven Programming

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/53

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

54 Terms

1
New cards

Streams

represent a source that provides a sequence of bytes, such as a file, an input/output (I/O) device, an interprocess communication pipe, or a TCP/IP socket.

2
New cards

Output streams

It refers to a printer, remote server location, or a printer where the data is written.

3
New cards

Input streams

It refers to a file or any source where the data can be read and assigned to the memory variables in the program.

4
New cards

System.IO

This namespace contains classes that allow to write and read files. This namespace needs to be included in all programs that use streams.

5
New cards

Byte-oriented

All files are ____ ______, meaning the data is written or read into the files in terms of bytes.

6
New cards

FileStream

It is a class that is used to create a byte-oriented stream attached to a file.

7
New cards

FileStream(string filename,FileMode mode)

The code to be used for creating a FileStream object is:

8
New cards

Mode

The _ parameter specifies how the file needs to be opened.

9
New cards

FileMode.Create

It creates a new output file, which will be overwritten if a file already exists.

10
New cards

FileMode.CreateNew

It creates a new output file that is not existing.

11
New cards

FileMode.Open

It opens an existing file.

12
New cards

FileMode.OpenOrCreate

It opens an existing. If not, it creates a new one.

13
New cards

FileMode.Truncate

It opens an existing file and truncates the content that already exists.

14
New cards

FileStream Constructor

The __ is used to open a file that has access to read or write.

15
New cards

FileMode.Create, FileMode.CreateNew, FileMode.Open, FileMode.OpenOrCreate, FileMode.Truncate

The options for FileMode are as follows: HINT: C CN O OOC T

16
New cards

ReadByte()

This method reads a single byte from a file and returns as an integer value.

17
New cards

Read()

This method reads the specified number of bytes from a file into an array.

18
New cards

WriteByte()

It writes the specified byte into the file.

19
New cards

Write()

It writes an array of bytes into the file.

20
New cards

Flush()

This method instantly writes the data into the file.

21
New cards

void Close()

This method closes the file, releasing the system resources that are allocated to it

22
New cards

ReadByte(), Read(), WriteByte(), Write(), Flush(), void Close()

This class also contains the following methods to perform read and write operations: HINT: RB R WB W F C

23
New cards

Seek()

To access a file randomly, position the file pointer inside the file at the required location. A file pointer determines the location of the next read/write operation to take place on the file. The method used to relocate the file pointer in the file is ____ (Harwani, 2015, p. 462). ______ is a method that allows setting the file position indicator of file pointer to the preferred location in the file.

24
New cards

long Seek(long n, SeekOrigin location)

The syntax for Seek() is:

25
New cards

Position

The file pointer can get or set the position using the _ property of Stream class.

26
New cards

bool CanRead

It returns true if the stream can be read.

27
New cards

bool CanSeek

It returns true if the stream supports position requests.

28
New cards

bool CanTimeout

It returns true if the stream can time out.

29
New cards

bool CanWrite

It returns true if the stream can be written.

30
New cards

long length

It contains the size of the stream.

31
New cards

int ReadTimeout

It indicates the time before a timeout occurs for read operations.

32
New cards

int WriteTimeout

It indicates the time before a timeout occurs for write operations.

33
New cards

bool CanRead, bool CanSeek, bool CanTimeout, bool CanWrite, long length, int ReadTimeout, int WriteTimeout

Aside from the Position property, these properties are commonly used:HINT: BCR BCS BCT BCW LL IRT IWT

34
New cards

StreamWriter, StreamReader

To perform a character-based file for managing text files, use character streams to read and write into the file. 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.

35
New cards

StreamWriter

It writes characters to a stream and contains several constructors.

36
New cards

SteamWriter(Stream stream)

It is used to create a character-based output stream.

37
New cards

StreamWriter(string fileName)

It is used to open a file directly.

38
New cards

SteamWriter(Stream stream), StreamWriter(string fileName)

StreamWriter writes characters to a stream and contains several constructors, such as the following:

39
New cards

Close(), Flush, Write, WriteLine

The StreamWriter class contains the following common methods: HINT: C F W WL

40
New cards

Close()

It closes the file.

41
New cards

Flush()

It instantly saves the file content from buffer to memory

42
New cards

Write()

Using a File stream class, this writes into the specified file.

43
New cards

WriteLine()

Line by line, it writes into a file.

44
New cards

StreamReader

This is a class that reads characters from a byte stream. StreamReader(Stream stream)

45
New cards

StreamReader(string fileName)

It specifies the name of the file to open.

46
New cards

StreamReader(Stream stream), StreamReader(string fileName)

StreamReader defines the following constructors:

47
New cards

Flush(), Close(), Read(), ReadLine(), ReadToEnd(), Peek(), Seek()

The StreamReader class also contains the following common methods:

48
New cards

Flush()

From buffer to memory, it instantly saves the file content.

49
New cards

Close()

It closes the file and is mandatory to this class.

50
New cards

Read()

From the file stream, it reads the content.

51
New cards

ReadLine()

From the given file stream, it reads the content line by line.

52
New cards

ReadToEnd()

From the current location until the end of the stream, it reads all characters.

53
New cards

Peek()

It returns the value in the stream without moving the file pointer.

54
New cards

Seek()

Sets the file pointer at the desired position in a file.