-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileProcess.cs
More file actions
70 lines (66 loc) · 2.43 KB
/
FileProcess.cs
File metadata and controls
70 lines (66 loc) · 2.43 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
61
62
63
64
65
66
67
68
69
70
namespace CPSC3130_Project
{
//This Class for File Processing
//Provide Get Data from file, Write Data to File
public class FileProcess
{
public FileProcess()
{
}
//Method Get Data from file. Return Data in User Data List
public List<String[]> GetArrayData(String fileName)
{
StreamReader read = new StreamReader(fileName);
List<String[]> _arrayData = new List<String[]>();
while (!read.EndOfStream)
{
//Read line
string line = read.ReadLine();
//Seperate the element by comma and put in the array.
string[] array = line.Split(',');
//Add array to List element.
_arrayData.Add(array);
}
read.Close();
return _arrayData;
}
//Method Get Data from file. Return Data in Character List
public List<String[]> GetCharData(String fileName)
{
StreamReader read = new StreamReader(fileName);
List<String[]> _charData = new List<String[]>();
while (!read.EndOfStream)
{
//Read line
string line = read.ReadLine();
//Seperate the element by comma and put in the array.
string[] array = line.Split(',');
//Add array to List element.
_charData.Add(array);
}
read.Close();
return _charData;
}
//Method Write the Type List of String in ARRAY Data parameter to FileName parameter
public void WriteFile (List<String[]> arrayData, String fileName)
{
StreamWriter write = new StreamWriter(fileName,append:true);
for (int i = 0; i < arrayData.Count; i++)
{
write.WriteLine(string.Join(",", arrayData[i]));
}
write.Close();
}
//Method Write the List of String Data parameter to FileName parameter
//Not use yet.
public void WriteFile(Dictionary<String,int> dictionaryData, String fileName)
{
StreamWriter writer = new StreamWriter(fileName);
for (int j = 0; j < dictionaryData.Count; j++)
{
writer.WriteLine($"{dictionaryData.ElementAt(j).Key},{dictionaryData.ElementAt(j).Value}");
}
writer.Close();
}
}
}