Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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 Parker212,257 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!