带有进度显示的文件拷贝模块

using System;
using System.IO;

namespace csmyCopy
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			FileStream fin, fout;
			Int64 len;
			Byte[] arrBuf = new byte[1428];

			Console.WriteLine ("Debug::Args->" +args.Length.ToString());

			if (args.Length != 2) {
				Console.WriteLine ("Usage: myCopy 
   
    
    
    
     
     ");
				return;
			}
			try {
				fin = new FileStream (args[0], FileMode.Open);
			} catch (Exception ex) {
				Console.WriteLine ("Crit::Retn->1,Evnt->Fail to open src");
				Console.WriteLine ("Crit::Msg->" + ex.Message);
				return;
			}
			try {
				fout = new FileStream (args[1], FileMode.Create);
			} catch (Exception ex) {
				Console.WriteLine ("Crit::Retn->2,Evnt->Fail to open dst");
				Console.WriteLine ("Crit::Msg->" + ex.Message);
				return;
			}

			len = fin.Length;
			Console.Write ("Info::Leng->");
			Console.Write (len);
			Console.WriteLine ();

			try {
				while (fin.Position < len) {
					fin.Read (arrBuf, 0, 1428);
					fout.Write (arrBuf, 0, 1428);
					if (fin.Position % 131072 == 0) {
						Console.Write ("Info::Curr->");
						Console.Write (fin.Position);
						Console.Write (",Perc->");
						Console.Write (fin.Position * 100 / len);
						Console.WriteLine ("%");
					}
				}
			} catch (Exception ex) {
				Console.WriteLine ("Crit::Retn->3,Evnt->Fail to copy");
				Console.WriteLine ("Crit::Msg->" + ex.Message);
			}


			fin.Close();
			fout.Close();
			Console.WriteLine ("Info::Retn->0,Evnt->Finished");
		}
	}
}

    
    
   
   

运行结果:
csmyCopy mono.2 mono.3

D:\>csmyCopy mono.2 mono.3
Debug::Args->2
Info::Leng->   704704512
Info::Curr->     7047180,Perc->  1%
Info::Curr->    14094360,Perc->  2%
Info::Curr->    21141540,Perc->  3%
Info::Curr->    28188720,Perc->  4%
Info::Curr->    35235900,Perc->  5%
Info::Curr->    42283080,Perc->  6%
Info::Curr->    49330260,Perc->  7%
...
Info::Curr->   669470676,Perc-> 95%
Info::Curr->   676516428,Perc-> 96%
Info::Curr->   683563608,Perc-> 97%
Info::Curr->   690610788,Perc-> 98%
Info::Curr->   697657968,Perc-> 99%
Info::Curr->   704704512,Perc->100%
Info::Retn->0,Evnt->Finished
D:\>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值