C#读写文件的例子

爱上不会游泳的鱼 爱上不会游泳的鱼 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现在有一个1.txt文件,内容是一个1,用二进制的方式把他读到另外一个文件2.txt中是49,不知道为什么是49(这个不重要),然后读2.txt文件,要读到的内容是1,怎么样读呢。读到的变量data是49,求救啊!!!!!!!!!!!
string pathbody = @"C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)" + "\\1.txt";
string pathheader = @"C:\Documents and Settings\Administrator\桌面\新建文件夹 (2)" + "\\2.txt";
byte[] arrFile=null;
using (FileStream fs2 = new FileStream(pathbody, FileMode.Open))
{
arrFile= new byte[1];
fs2.Read(arrFile, 0, 1);//读1.txt的文件
using (StreamReader sr = new StreamReader(fs2))
{
using (StreamWriter sw1 = new StreamWriter(pathheader, true))
{
for (int i = 0; i < 1; i++)
{
sw1.Write(arrFile[i]);

}
}
}

}

using (FileStream fsBody = new FileStream(pathheader, FileMode.Open, FileAccess.Read))
{

using (StreamReader sw1 = new StreamReader(fsBody))
{
string str = sw1.ReadLine();
byte[] demo = System.Text.Encoding.Default.GetBytes(str);
string data = System.Text.Encoding.Default.GetString(demo);

}
}
...全文
评论 13
收藏 已收藏
分享
返回顶部
爱上不会游泳的鱼
C# 111,129 成员 642,540 内容