//編碼格式
//產生亂碼的原因,就是你儲存這個檔案所採用的編碼跟你開啟這個檔案所採用的編碼格式不一樣
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();