-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUssing files StreamWriter and StreamReader
59 lines (55 loc) · 1.52 KB
/
Ussing files StreamWriter and StreamReader
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
double pi = Math.PI;
FileStream f = new FileStream("file.txt",FileMode.OpenOrCreate,FileAccess.ReadWrite,FileShare.ReadWrite);
try
{
using(StreamWriter sw = new StreamWriter(f))
{
String userinput = Console.ReadLine();
if (f.Length > 1)
{
sw.Write(userinput);
sw.Write("\r\n");
}
else
{
sw.WriteLine(userinput);
sw.Write("\r\n");
}
}
}
catch(IOException ioe)
{
Console.WriteLine(ioe);
}
catch(Exception e)
{
Console.WriteLine(e);
}
int line;
using (StreamReader sr = new StreamReader("file.txt"))
{
try
{
Console.WriteLine(sr.ReadToEnd());
Console.ReadKey();
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
}
}
}