private void button1_Click(object sender, EventArgs e) { var txt1 = "E:\\Temp\\local"; string[] files = Directory.GetFiles(txt1, "*.txt"); foreach (string file in files) { execFile(file); } } void execFile(string file) { int i = 0; var eType = EncodingType.GetType(file); var lines = File.ReadAllLines(file, eType); StreamWriter sw = new StreamWriter(file, false, eType); while(i<lines.Length) { sw.WriteLine(lines[i].Replace("开始", "kaizhan")); i++; } sw.Close(); }
EncodingType参考源:https://www.cnblogs.com/guyun/p/4262587.html
原文地址:https://www.cnblogs.com/edwardorchis/p/10306729.html
时间: 2024-10-09 06:04:45