private List<string> readFileToList(string fileName)
{
FileStream fs = new FileStream(fileName FileModeOpen FileAccessRead);
List<string> list = new List<string>();
StreamReader m_streamReader = new StreamReader(fs);//中文乱码加上SystemTextEncodingDefault或则SystemTextEncodingGetEncoding(GB)
//使用StreamReader类来读取文件
m_streamReaderBaseStreamSeek( SeekOriginBegin);
// 从数据流中读取每一行直到文件的最后一行并在richTextBox中显示出内容
string strLine = m_streamReaderReadLine();
while (strLine != null)
{
listAdd(strLine);
strLine = m_streamReaderReadLine();
}
//关闭此StreamReader对象
m_streamReaderClose();
return list;
}
private void writeListToFile(List<string> pList string myFileName)
{
//创建一个文件流用以写入或者创建一个StreamWriter
SystemIOFileStream fs = new SystemIOFileStream(myFileName FileModeOpenOrCreate FileAccessWrite);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriterFlush();
// 使用StreamWriter来往文件中写入内容
m_streamWriterBaseStreamSeek( SeekOriginBegin);
// 把richTextBox中的内容写入文件
for (int i = ; i < pListCount; i++)
{
m_streamWriterWriteLine(pList[i]);
}
//关闭此文件
m_streamWriterFlush();
m_streamWriterClose();
}
//测试 by gisoracle
private void button_Click(object sender EventArgs e)
{
List<string> slist = readFileToList(@C:\转换\txt);
writeListToFile(slist @C:\转换\txt);
}