文件与数组转换
//将文件内容读到数组
public string[][] ReadFileToArray(string strFileName)
{
//定义数组列表
List<string[]> listSolarData = new List<string[]>();
//实例化流操作对象
using (StreamReader readerSolarData = new StreamReader(strFileName))
{
string strLine = null;
//读取数据一直到空
while ((strLine = readerSolarData.ReadLine()) != null)
{
listSolarData.Add(Regex.Split(strLine.Trim(), ","));
}
}
//写二维字符串数组
string[][] arraySolarData = listSolarData.ToArray();
listSolarData.Clear();
GC.Collect();
return arraySolarData;
}
//将数组写到文件
public void ArryWriteToFile(string strFileName, string strToWrite)
{
try
{
System.IO.StreamWriter writerSolarData = new System.IO.StreamWriter(strFileName, true);
//写信息
writerSolarData.WriteLine(strToWrite);
writerSolarData.Close();
}
catch (Exception ex)
{
LogInfo log = new LogInfo();
log.WriteLog(ex.Message);
}
}