c#读写文件
其实我觉得C#这方便比Java方便得多
直接上代码了不墨迹了
啥不懂的评论就OK 随时回复
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FileStreamDemo
{
class Program
{
static void Main(string[] args)
{
String source = @"C:\Users\liujiamei\Desktop\tomcatsever.txt";
String target = @"C:\Users\liujiamei\Desktop\tomcatseverr2.txt";
copyFile(source, target);
Console.WriteLine("ok");
Console.ReadKey();
}
public static void copyFile(String source, String target)
{
using (FileStream fsRead = new FileStream(source, FileMode.Open, FileAccess.Read))
{
using (FileStream fsWrite = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
{
byte[] buffer = new byte[1024 * 1024 * 5];
while (true) {
int r = fsRead.Read(buffer, 0, buffer.Length);
if (r == 0)
{
break;
}
fsWrite.Write(buffer, 0, r);
}
}
}
}
}
}