C# 如何读取一个文件夹下的多个文件内容

用C#语言将在C:\111文件下有1.txt2.txt3.txt三个文件如何读取这三个文件的内容并把他保存到一个文件下。请给出具体步骤或代码,具体些,谢谢!最好用循环的方... 用C#语言将 在C:\111文件下有 1.txt 2.txt 3.txt三个文件 如何读取这三个文件的内容 并把他保存到一个文件下。
请给出具体步骤或代码,具体些,谢谢!
最好用循环的方法
展开
 我来答
百度网友f43968375
推荐于2017-11-21 · TA获得超过434个赞
知道小有建树答主
回答量:591
采纳率:0%
帮助的人:514万
展开全部
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(“文件夹路径”);
FileInfo[] ff = di.GetFiles("*.txt");//只取文本文档
string ss = "";//存放内容
foreach (FileInfo temp in ff)
{
using (StreamReader sr = temp.OpenText())
{
ss += sr.ReadToEnd();//内容追加到ss中
}
}
File.AppendAllText("要保存的文件路径", ss);//保存到一个文件里
HAL9000PLUS
2009-06-22 · TA获得超过1279个赞
知道小有建树答主
回答量:663
采纳率:0%
帮助的人:709万
展开全部
using System;
using System.Collections.Generic;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// 用二进制方式读,以兼容非文本的文件。
using (BinaryWriter bw = new BinaryWriter(File.OpenWrite("c:\\111\\result.txt")))
{
using (BinaryReader br = new BinaryReader(File.OpenRead("C:\\111\\1.txt")))
{
bw.Write(br.ReadBytes((int)br.BaseStream.Length));
}
using (BinaryReader br = new BinaryReader(File.OpenRead("C:\\111\\2.txt")))
{
bw.Write(br.ReadBytes((int)br.BaseStream.Length));
}
using (BinaryReader br = new BinaryReader(File.OpenRead("C:\\111\\3.txt")))
{
bw.Write(br.ReadBytes((int)br.BaseStream.Length));
}
}
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式