Dominik Huber4,631 Points
Can someone please explain this to me in more details? Console.WriteLine(Console.ReadLine()) makes no sense to me.
I have a few questions.
So the first code I don't get is this:
What exactly does the file.FullName return? Documentation says it returns the full path of the file. But why? I think we already have the full path with this code:
fileName = Path.Combine(directory.FullName, "data.txt");
Console.SetIn(reader); --> What is this doing exactly? It passes in the "Stream" and does what exactly?
So whenever I call Console.ReadLine() now I can't write anything to it, because the "StreamReader" passes in the string from the data.txt file? And it gets passed in every time I call Console.ReadLine(), until I close the stream? Please if someone could explain me this like I'm five would be very nice.
Steven Parker201,319 Points
The "SetIn" method determines where the input will come from. It's like setting a switch. If you choose a stream, it will take the input from the stream instead of from typing to the actual console.
If you want stream input and console input you would not redirect the console. Instead you can use the read methods of the stream itself.
James ChurchillTreehouse Teacher
In order to retrieve the information for the "data.txt" file, we need the full path to that file, which is what this code is doing:
var fileName = Path.Combine(directory.FullName, "data.txt");
Then, after we've retrieved the file information and verified that the file exists, we can use the FileInfo object's
FullName property to get the full path to the file. As you've noted, we already had the value on hand in the
fileName variable, so using the FileInfo
FullName property later on is a bit redundant.
I hope that helps.
Thank you, Steven! You are the person who adds value to Treehouse!