-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiles1.cs
More file actions
60 lines (55 loc) · 1.78 KB
/
Files1.cs
File metadata and controls
60 lines (55 loc) · 1.78 KB
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
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpProgramming
{
/// <summary>
/// Files-FileStream-(StreamReader-StreamWriter)-helper classes
/// Filestream - inherited from Stream class(abstract)
/// </summary>
internal class Files1
{
public static void Main()
{
FileInfo fileInfo = new FileInfo(@"E:\Trainees.txt");
//StreamWriter
//FileStream fs = fileInfo.Open(FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
//StreamReader
//FileStream fs = fileInfo.Open(FileMode.Open,FileAccess.ReadWrite,FileShare.ReadWrite
//Append Mode - FileAccess can be only Write
FileStream fs = fileInfo.Open(FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
//WRITE OPERATION
StreamWriter sw = new StreamWriter(fs);//Trainees.txt
try
{
sw.WriteLine("Welcome to Files StreamReader and StreamWriter Concepts");
}
catch (FileNotFoundException e)
{
Console.Write(e.ToString());
}
finally
{
sw.Close();
fs.Close();
}
//READ OPERATION
//StreamReader sr = new StreamReader(fs);//Trainees.txt
//try
//{
// string contents;
// contents=sr.ReadToEnd();
// Console.WriteLine(contents);
//}catch(FileNotFoundException e)
//{
// Console.WriteLine(e.Message);
//}finally
//{
// sr.Close();
// fs.Close();
//}
}
}
}