-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileManager.cs
55 lines (50 loc) · 1.04 KB
/
FileManager.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
53
54
55
using System;
using System.IO;
namespace EllyGGEpochFilter
{
public static class FileManager
{
public static bool ReadFile(string folder, string fileName, out string content, out string errorMessage)
{
content = null;
try
{
using (FileStream fs = new FileStream(Path.Combine(folder, fileName.Trim()), FileMode.Open))
{
using (StreamReader sr = new StreamReader(fs))
{
content = sr.ReadToEnd();
}
}
}
catch(Exception e)
{
errorMessage = e.ToString();
return false;
}
errorMessage = null;
return true;
}
public static bool SaveFile(string folder, string fileName, string content, out string errorMessage)
{
try
{
using (FileStream fs = new FileStream(Path.Combine(folder, fileName.Trim()), FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine(content);
sw.Flush();
}
}
}
catch(Exception e)
{
errorMessage = e.ToString();
return false;
}
errorMessage = null;
return true;
}
}
}