FileStream fs = new FileStream(@"..\HHH\123.csv", FileMode.Open, FileAccess.Read, FileShare.None); StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding(936)); string str = ""; while (str != null)//循环调取,调取出来的是带逗号的字符串 { str = sr.ReadLine(); Console.WriteLine(str); if (str != null) { if (str.Contains(",") == true) { Console.WriteLine("hhh"); } else { Console.WriteLine("结束"); break; } } else { break; } } sr.Close();
以上是CSV的读取。
FileStream fs = new FileStream(@"..\HHH\123.csv", FileMode.Open, FileAccess.Write, FileShare.None); StreamWriter sw = new StreamWriter(fs,Encoding.UTF8); sw.WriteLine("123,33,55,785,2165136"+"\n"+"58585858"); sw.Close();
以上是CSV的写入,字符串格式要用逗号隔开。