I have a text file named C:/test.txt:
1 2 3 4 5 6
I want to read every number in this file using StreamReader.
How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you really need to use a
StreamReaderto do this?(Obviously if it’s impractical to read the entire file in one hit then you’ll need to stream it, but if you’re able to use
File.ReadAllTextthen that’s the way to do it, in my opinion.)For completeness, here’s a streaming version: