//编码格式
//产生乱码的原因,就是你保存这个文件所采用的编码跟你打开这个文件所采用的编码格式不一样
string str = "今天天气好晴朗处处好风光";
//需要将字符串转换成字节数组
byte[] buffer = Encoding.Default.GetBytes(str);
File.WriteAllBytes(@"C:\Users\admin\Desktop", buffer);
Console.WriteLine("写入成功");
Console.ReadKey();
//一个返回数组 操作行数据
string[] contents = File.ReadAllLines(@"C:\Users\admin\Desktop.txt", Encoding.Default);
foreach (string item in contents)
{
Console.WriteLine(item);
}
byte[] buffer = File.ReadAllBytes(@"C:\Users\admin\Desktop\a.txt");
string s = Encoding.Default.GetString(buffer);
Console.WriteLine(s);
//一个返回字符串 操作整体数据
string str = File.ReadAllText(@"C:\Users\admin\Desktop\a.txt", Encoding.Default);
Console.WriteLine(str);
Console.ReadKey();
File.WriteAllLines(@"C:\Users\admin\Desktop\a.txt", new string[] { "aoe", "ewu" });
Console.WriteLine("ok");
File.WriteAllText(@"C:\Users\admin\Desktop\a.txt", "张三实力");
Console.WriteLine("ok");
Console.ReadKey();
File.AppendAllText(@"C:\Users\admin\Desktop\a.txt", "看我有没有把你覆盖掉");
Console.WriteLine("OK");
Console.ReadKey();