程序是这样的
public struct Point
{
public double X;
public double Y;
}
public void ReadTxtAndSaveAsDir()
{
FileSystemWatcher watcher = new FileSystemWatcher();
string path = "D:\\Zane自动合成";
//判断文件夹是否存在
if (Directory.Exists(path))
{
DirectoryInfo directoryInfo = new DirectoryInfo(path);
FileInfo[] files = directoryInfo.GetFiles();
for (int i = files.Length - 1; i < files.Length; i++)
{
if (files[i].Extension.Equals(".txt")) //判断是否为txt文件
{
//文本文件完整路径\并且读入所有行
string[] strs = File.ReadAllLines(path +"/"+ files[i].Name);
// 创建字典
Dictionary<double, double> myDictionary = new Dictionary<double, double>();
// 让过前两行,从第三行开始处理
try
{
for (int j = 2; j < strs.Length; j++)
{
string line = strs[j];
// 拆分行
string[] v = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Point p;
// 获取Y(第一列)
p.X = double.Parse(v[0]);
// 获取Y(第二列)
p.Y = double.Parse(v[1]);
myDictionary.Add(p.X, p.Y);
}
strs = null;
// 至此,所有的数据点都在字典中了……
//if (myDictionary.ContainsKey(274) || myDictionary.ContainsKey(269))
//{}
double x = myDictionary[274];
double y = myDictionary[269];
//double sub = x-y;
double div = x / y;
WriteIn(x, y, div);
textBox2.AppendText(
"274nm = " + x + ", " + "269nm = " + y + ", " + "274nm / 269nm = " + div+"\r\n");
if (div > 1.2 && x > 0.01)
{
Collect();
}
}
catch (FormatException)
{ }
}
}
}
else { Directory.CreateDirectory(path); }
}
其他部分都能很好的运行,但是每次到
string[] strs = File.ReadAllLines(path +"/"+ files[i].Name);
这个部分就会报错
请大神指导