发布网友 发布时间:2024-10-08 04:54
共3个回答
热心网友 时间:2024-11-11 12:35
private void button1_Click(object sender, EventArgs e)
{
try
{
DirectoryInfo dir = new DirectoryInfo(textBox1.Text.Trim());
FileInfo[] files = dir.GetFiles("*.txt");
foreach (FileInfo file in files)
{
string fileName = file.FullName;
FileStream fs = new FileStream(fileName, FileMode.Open);
StreamReader sr = new StreamReader(fs);
string str = sr.ReadToEnd();
str = str.Replace("192.168.1.1", "127.0.0.1");
sr.Close();
fs.Close();
file.Delete();
FileStream fs1 = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs1);
sw.Write(str);
sw.Flush();
sw.Close();
fs1.Close();
MessageBox.Show("处理成功!");
}
}
catch (Exception ee)
{
MessageBox.Show("您输入的目录位置有问题!");
}
}
热心网友 时间:2024-11-11 12:35
this.Label1.Text = Lable1.Text.Replace("192.168.1.1", "127.0.0.0");热心网友 时间:2024-11-11 12:39
用Flie读取文件,获得文本内容.