文件流读取与写入
写入: string strExt = System.IO.Path.GetExtension(fromPath);//扩展名 var file = NP_Global.TemplatePath + model.ModelName + model.ModelExt;System.IO.FileStream fs = new System.IO.FileStream(file, F
写入:
string strExt = System.IO.Path.GetExtension(fromPath);//扩展名
var file = NP_Global.TemplatePath + model.ModelName + model.ModelExt;
System.IO.FileStream fs = new System.IO.FileStream(file, FileMode.OpenOrCreate, FileAccess.Read);
byte[] fileByte = new byte[fs.Length];
fs.Read(fileByte, 0, (int)fs.Length);
model.FileDataJson = Convert.ToBase64String(fileByte);//转化为字符串通过json传值,保存到数据库时转化为:Convert.FromBase64String(model.FileDataJson)
读取:
model.FileDataJson = Convert.ToBase64String(fileData);
byte[] fileData = Convert.FromBase64String(model.FileDataJson);
var file = NP_Global.TemplatePath + model.ModelName + model.ModelExt;
public static void SaveModel(string file, byte[] fileData)
{
FileStream fs = new FileStream(file, FileMode.Create);
BinaryWriter sw = new BinaryWriter(fs);
//开始写入
sw.Write(fileData);
//清空缓冲区
sw.Flush();
//关闭流
sw.Close();
sw.Dispose();
fs.Close();
fs.Dispose();
}

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)