using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace CSVDemo
{
///
/// CSVUtil is a helper class handling csv files.
///
public class CSVUtil
{
private CSVUtil()
{
}
public static void WriteCSV( string filePathName,Listls)
{
WriteCSV(filePathName, false ,ls);
}
public static void WriteCSV( string filePathName, bool append, Listls)
{
StreamWriter fileWriter= new StreamWriter(filePathName,append,Encoding.Default);
{
fileWriter.WriteLine(String.Join (“,",strArr) );
}
fileWriter.Flush();
fileWriter.Close();
}
public static ListReadCSV( string filePathName)
{
Listls = new List();
StreamReader fileReader= new StreamReader(filePathName);
string strLine= "" ;
while (strLine != null )
{
strLine = fileReader.ReadLine();
if (strLine != null && strLine.Length>0)
{
ls.Add(strLine.Split( ',' ));
}
}
fileReader.Close();
return ls;
}
}
}
|