C#如何读取多个txt文件到数据库,然后同时删除读写过的txt文件!

如题所述

楼主是想把文件保存到数据库当中?
很简单,抱歉我不能给你写完整代码。
第一步将文件转二进制
string filePath = "路径/文件名.txt";
System.IO.FileStream stream = new System.IO.FileInfo(filePath).OpenRead();
byte[] fileData = new byte[stream.Length];
stream.Read(fileData, 0, Convert.ToInt32(stream.Length));
stream.Close();
第二步数据库建表(以Oracle为例)
Create table TxtFileTable(fileName varchar2(20),fileData blob);
第三步写数据库
自己写,很简单,连接数据库,用insert语句写入;
第四步删除文件
File.Delete(filePath);
温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜