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 FileName=@"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();
}

posted on 2018-10-18 10:08  Ssumer  阅读(4457)  评论(0编辑  收藏  举报

导航