C#如何读写文件

来源:百度知道 编辑:UC知道 时间:2024/06/14 13:14:59
我想读写WindowsMediaPlayer播放列表文件中存放的歌曲路径...等着交毕设...求好心人帮忙...

public static void Main()
{
string[] s = { "c:\\", "d:\\", "e:\\", "f:\\" };
using (StreamWriter sw = new StreamWriter("1.ini", false))//false为直接覆盖该文件,true就直接添加在文件末尾
{
foreach (string t in s)
{
sw.WriteLine(t);
}
}

using (StreamReader sr = new StreamReader("1.ini"))
{
string ss = sr.ReadLine();
while (ss != null)
{
Console.WriteLine(ss);
ss = sr.ReadLine();
}
}
}

我给你一个例子你参考下吧

我就懂一般的文件读写···如果你要XML的就自己找下吧
下面高人说有

public static void Main()
{
string[] s = { "c:\\", "d:\\", "e:\\", "f:\\" };
using (StreamWriter sw = new StreamWriter("1.ini", false))//false为直接覆盖该文件,true就直接添加在文件末尾
{