using System;
using System.IO;
using System.Text;
namespace tab_delimited
{
class Program
{
static void Main(string[] args)
{
string fileName = @"C:\Temp\Adi.txt";
try
{
// Check if file already exists. If yes, delete it.
if (File.Exists(fileName))
{
File.Delete(fileName);
}
var delimiter = "\t";
var newline = "\n";
StringBuilder sb = new StringBuilder();
sb.Append("1" + delimiter + "2" + delimiter + "3" + delimiter + "4" + delimiter + "5");
sb.Append(newline);
sb.Append("6" + delimiter + "7" + delimiter + "8" + delimiter + "9" + delimiter + "10");
sb.Append(newline);
sb.Append("11" + delimiter + "12" + delimiter + "13" + delimiter + "14" + delimiter + "15");
sb.Append(newline);
sb.Append("16" + delimiter + "17" + delimiter + "18" + delimiter + "19" + delimiter + "20");
// Create a new file
using (FileStream fs = File.Create(fileName))
{
//// Add some text to file
Byte[] title = new UTF8Encoding(true).GetBytes(sb.ToString());
fs.Write(title, 0, title.Length);
}
// Open the stream and read it back.
using (StreamReader sr = File.OpenText(fileName))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
Console.ReadLine();
}
catch (Exception Ex)
{
Console.WriteLine(Ex.ToString());
}
}
}
}
No comments:
Post a Comment