I am trying to create a new file with a specific length. By using below code, the file gets created. The problem is the length of the file created is 0kb's. Also, the text under stream writer is not written in the file.
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
namespace Filesize
{
class Program
{
static void Main(string[] args)
{
FileInfo fi = new FileInfo(@"D:\\demotext2.txt");
StreamWriter sw = new StreamWriter(@"D:\\demotext2.txt", true);
try
{
while (fi.Length >= (2 * 1024 * 1024))
{
sw.WriteLine("Demo File");
}
}
catch (Exception ex)
{
ex.ToString();
}
}
}
}