I can get streamreader to work on one file, but can't code right to get it to read multiple.
The first code is where I have it working fine. The second one just produces a dos window with no date.
This is the one I can't figure out what is wrong. No errors being produced, but not getting the result I want either.Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace readtest { class Program { static void Main(string[] args) { StreamReader sr = new StreamReader("C:\\Users\Random.txt"); string str = sr.ReadLine(); string[] words = str.Split('|'); foreach (string word in words) { Console.WriteLine(word); } Console.ReadKey(); } } }
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string[] files = Directory.GetFiles("C:\\Users", ".txt"); foreach (string file in files) { StreamReader sr = new StreamReader(file); string str = sr.ReadLine(); { Console.WriteLine(file); } } Console.ReadKey(); } } }




Reply With Quote