I'm having trouble with coppying an array of strings to a new text file, When I create a new file,The file was created,but when I try to copy the array to the new text file,the file stays empty no matter what I tried.
I tried to use "using" to create the file,I have also tried to create a new text file without "using" and made sure not to forget to use "file.Close();" ,nothing seems to work.
any suggestions?
Jonathan.
this is my corrent code (the problem is located only after the "for" loop):
static void Main(string[] args) {
string fileContent = File.ReadAllText("FreeText.txt");
string[] chars = fileContent.Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
for(int i =0;i<chars.Length;i++) {
if (i % 2 != 0)
chars[i] = chars[i].ToUpper();
else
chars[i] = chars[i].ToLower();
}
using( FileStream fs = new FileStream(@"C:\Users\Yonatan\Documents\Visual Studio 2013\Projects\Clab2\Clab2\bin\Debug\Test.txt",
FileMode.OpenOrCreate,
FileAccess.Write)) {
StreamWriter writer = new StreamWriter(fs);
writer.WriteLine(chars);
fs.Flush();
}
}