1. 程式人生 > >C# 開啟檔案 儲存檔案

C# 開啟檔案 儲存檔案

string path = @"C: \Users\users\Desktop\xxxx.txt";// 檔案路徑
FileStream filestream = new FileStream(path, FileMode.Open);

byte[] bt = new byte[filestream.Length];

//呼叫read讀取方法
filestream.Read(bt, 0, bt.Length);
string base64Str = Convert.ToBase64String(bt);

filestream.Close();

 

string [email protected]

"C: \Users\users\Desktop\xxxx.txt";// 檔案路徑

lsitstr 需要儲存的字串

using (FileStream fileStream = File.Create(FileName))
{
byte[] bytes = new UTF8Encoding(true).GetBytes(liststr);
fileStream.Write(bytes, 0, bytes.Length);
fileStream.Close();
}