C#中txt文档的读写问题
我想从A文档中读取内容,然后把A文档的内容写入到B文档中。但是只能从A中读到内容,但是无法写入到B文档中,代码执行完后,B文档一片空白,本人是C#菜鸟,求指教,代码如下:...
我想从A文档中读取内容,然后把A文档的内容写入到B文档中。但是只能从A中读到内容,但是无法写入到B文档中,代码执行完后,B文档一片空白,本人是C#菜鸟,求指教,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace FileReadAndWrite
{
class Program
{
static void Main(string[] args)
{
string data = null;
string filePathA = "D:/A.txt";
string filePathB = "D:/B.txt";
StreamWriter writer = new StreamWriter(filePathB);
StreamReader reader = new StreamReader(filePathA);
while ((data = reader.ReadLine()) != null)
{
Console.WriteLine(data);
writer.WriteLine(data);
}
Console.ReadKey();
}
}
} 展开
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace FileReadAndWrite
{
class Program
{
static void Main(string[] args)
{
string data = null;
string filePathA = "D:/A.txt";
string filePathB = "D:/B.txt";
StreamWriter writer = new StreamWriter(filePathB);
StreamReader reader = new StreamReader(filePathA);
while ((data = reader.ReadLine()) != null)
{
Console.WriteLine(data);
writer.WriteLine(data);
}
Console.ReadKey();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询