-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorage.cs
39 lines (34 loc) · 1.14 KB
/
Storage.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
using System.IO;
using System.Collections;
using System.Text;
namespace econrpg
{
public class Storage
{
private static String dir = Directory.GetCurrentDirectory();
private static String[] storageFiles = {"agents", "clearingHouse"};
private Dictionary<String, FileStream> fileStreams;
public Storage()
{
this.fileStreams = new Dictionary<String, FileStream>();
foreach (String file in storageFiles)
{
String filePath = dir + "/storage/" + file + ".txt";
fileStreams.Add(file, File.Create(filePath));
}
}
public void writeLine(String target, String content)
{
if (!storageFiles.Contains(target)) return;
UTF8Encoding encode = new UTF8Encoding(true);
fileStreams[target].Write(encode.GetBytes(content + "\n"), 0, encode.GetByteCount(content + "\n"));
}
public void closeStreams()
{
foreach (KeyValuePair<String, FileStream> stream in this.fileStreams)
{
stream.Value.Close();
}
}
}
}