检查空白csv文件,循环查询,

时间:2014-12-04 22:17:59

标签: csv null

我试图阻止空csv文件导致我的简单采样程序出错,只需从文件夹中的每个.csv文件中获取2个值,

我有空检查,现在可以捕获它,但我不确定如何重新构造我的代码,因此它将数组中的文件跳到下一个,非常欢迎任何帮助,

    foreach (string name in array1)
    {
        // sampling engine loop here, take first line only, first column DateTimeStamp and second is Voltage
        Console.Write("\r      Number of File currently being processed = {0,6}", i);
        i++;
        var reader = new StreamReader(File.OpenRead(name)); // Static for testing only, to be replaced by file filter code

        var line = reader.ReadLine();
        if (line == null)
        {
            Console.WriteLine("Null value detected");
            Console.ReadKey();
            break;
        }
        var values = line.Split(',');

                     reader.ReadLine();
            if (values.Length == 89)
            {
                using (StreamWriter outfile = new StreamWriter(@"C:\\SampledFileResults.txt", true))
                {
                    string content = "";
                    {
                        content = content + values[0] + ",";
                        content = content + values[9] + ",";
                    }
                    outfile.WriteLine(content);
                    Console.WriteLine(content);
                }
            }                
    }
Console.WriteLine("SAMPLING COMPLETED");

0 个答案:

没有答案