filestream_writeto_file.htm

using System;
using System.IO;
//csc filestream_write_in_file.cs
//to run this example you must have created directory \ folder to write
//some text, otherwise you may commit access violation
//C:\my_dir_3\temp
namespace file_read_write
{
public class write_text
{
public static void process(string s )
{
string path = "";
path += @s ;
//path += s ;
Console.WriteLine("The path reconstructed : " + path);
try
{
if (File.Exists(path))
{
File.Delete(path);
}

using (StreamWriter sw = new StreamWriter(path))
{
Console.WriteLine("Enter some text below");
string str = Console.ReadLine();
sw.WriteLine(str);

}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
finally {}
}

}

class Test
{

public static void Main()
{

Console.Write("Existing path and new text file : ");
string str =Console.ReadLine();
write_text.process( str);
Console.ReadLine();
}
}
}