AS SSD Managing Input and Output Flashcards
(27 cards)
How can data be very easily input?
Data can be easily input using the console, through the use of the Console.ReadLine() method, provided that the data that the user has input is stored in a variable to be used elsewhere in the program.
How is data outputted back to the screen?
Output is displayed back to the user using the Console.WriteLine() method, provided a Console application has been created and used.
How can output data be manipulated?
By using a number of string handling methods.
What method converts all output into upper case characters?
ToUpper() converts all data which has been output into upper case characters.
Which method converts output into lower case characters?
ToLower() converts all the data which has been input into lower case characters.
Which method joins two strings together?
Concat() joins two strings together.
Which method checks if a string contains a series of characters?
Contains() checks if a string contains a series of characters.
What method replaces part of a string with another?
Replace() replaces one part of a string with another.
What method splits a string?
Split() splits a string based on a specific “delimiter”. E.g. Every time a string appears.
What is the easiest way to write to a text file?
It is to use the StreamWriter.
What is a “stream”?
A “stream” is a method used to read or write data in a continuous flow. E.g. when writing data to a file, a StreamWriter will write all the text to the file.
What is important when using a StreamWriter?
It is important to close the StreamWriter when you have finished writing to a file. Without closing the writer, the data may not be written to the file.
What else is also important in relation to using a StreamWriter?
The path you use is also important.
What happens if the path is correct but the file has not been created?
Then the file will be created.
What happens if the path is wrong?
Then an error will be produced.
What method when the code is run again will overwrite the data already held in the file?
The WriteLine() method will.
How would you get around the issue that data is being overwritten in the file?
You would add an additional parameter into the StreamWriter class.
What parameter would be reasonable to use to fix data being overwritten?
A “path” parameter that is a Boolean value which tells the writer if it is true or false that the text will be appended to the file.
What is another way to write to text files?
You can use the FileStream.
What is the difference between the FileStream and the StreamWriter?
The StreamWriter will write data to a text file by handling raw text, such as strings when it writes data to a file. However, the FileStream will directly interact with the file at a more basic level as it deals with the raw bytes in the file.
What format must the data be in in order for the FileStream to use the data?
The data must be in a raw binary format.
What happens when the FileStream is created?
Two parameters will use the specified location and the “Create” mode will allow a file to be created if it doesn’t exist in the specified location. Or if it does exist then the file will overwrite the data already stored in it.
What else can you do with a text file?
It is also possible to read from a text file using both the StreamReader and the FileStream.
What should you remember to do with the StreamReader?
It is vital to close the StreamReader once you have finished reading the data from the file.