private string _filePath = @"1.txt";
//查詢文件是否存在,如果不存在,則創建
if (!File.Exists(_filePath))
{
using (File.Create(_filePath))
{
}
}
using (StreamReader sr = new StreamReader(_filePath))
{
//string str = sr.ReadLine();//讀一行
string str = sr.ReadToEnd();//讀到底
if (!string.IsNullOrWhiteSpace(str))
{
txtRtsp.Text = str;
}
}
//保存地址:
using (StreamWriter sw = new StreamWriter(_filePath)) //將覆蓋原有內容
//using (StreamWriter sw = new StreamWriter(_filePath,true))//在原有內容上追加
{
sw.Write(rtsp);
}
//循環讀多行
String line;
while ((line = sr.ReadLine()) != null)
{
this.ListBox1.Items.Add("line "); //增加讀出的內容到listbox
i++;
}