using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
if(File.Exists("D:\\c#\\vadi.txt"))
Console.WriteLine("File already exits");
else{
File.Create("D:\\c#\\vadi.txt");
Console.WriteLine("created");
}
int ch;
do{
Console.WriteLine("Enter ypur choice:\n1.Read\n2.Write\n3.Append");
ch=Convert.ToInt16(Console.ReadLine());
switch(ch)
{
case 1:
Console.WriteLine("Reading the file");
string s=File.ReadAllText("D:\\c#\\vadi.txt");
string[] st = new string[10];
st=File.ReadAllLines("D:\\c#\\vadi.txt");
for(int m=0;m<st.Length;m++)
Console.WriteLine(st[m]);
Console.WriteLine(s);
break;
case 2:
Console.WriteLine("Enter the String to be entered:");
string str=Console.ReadLine();
File.WriteAllText("D:\\c#\\vadi.txt",str);
break;
case 3:
Console.WriteLine("Enter the contents to be appended:");
string str1=Console.ReadLine();
File.AppendAllText("D:\\c#\\vadi.txt",str1);
break;
}
}while(true);
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
if(File.Exists("D:\\c#\\vadi.txt"))
Console.WriteLine("File already exits");
else{
File.Create("D:\\c#\\vadi.txt");
Console.WriteLine("created");
}
int ch;
do{
Console.WriteLine("Enter ypur choice:\n1.Read\n2.Write\n3.Append");
ch=Convert.ToInt16(Console.ReadLine());
switch(ch)
{
case 1:
Console.WriteLine("Reading the file");
string s=File.ReadAllText("D:\\c#\\vadi.txt");
string[] st = new string[10];
st=File.ReadAllLines("D:\\c#\\vadi.txt");
for(int m=0;m<st.Length;m++)
Console.WriteLine(st[m]);
Console.WriteLine(s);
break;
case 2:
Console.WriteLine("Enter the String to be entered:");
string str=Console.ReadLine();
File.WriteAllText("D:\\c#\\vadi.txt",str);
break;
case 3:
Console.WriteLine("Enter the contents to be appended:");
string str1=Console.ReadLine();
File.AppendAllText("D:\\c#\\vadi.txt",str1);
break;
}
}while(true);
Console.Read();
}
}
}
No comments:
Post a Comment