-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileOperation.cs
52 lines (51 loc) · 1.61 KB
/
FileOperation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
namespace FileHandleDemo
{
class FileOperation
{
public void CreateFile()
{
string path = @"C:\Users\Admin\Desktop\demo.txt";
if (!File.Exists(path))
{ using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("My name is Vishnu");
sw.WriteLine("I am from Guntur");
sw.WriteLine("Now Ia am staying at Sholinganallur");
sw.Flush();
}
}
}
public void DisplayFile()
{
string path = @"C:\Users\Admin\Desktop\demo.txt";
using (StreamReader sr = File.OpenText(path))
{
string s;
s = File.ReadAllText(path);
Console.WriteLine(s);
}
}
public void AddToFile()
{ string path = @"C:\Users\Admin\Desktop\demo.txt";
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("lalalalalalalalallalalalallalala");
sw.WriteLine("");
sw.WriteLine("No more arguments");
sw.Flush();
}
}
public void DeleteFile()
{
string path = @"C:\Users\Admin\Desktop\demo.txt";
File.Delete(path);
Console.WriteLine("File Deleted Successfully...");
}
}
}