带有进度显示的文件拷贝模块
2015-09-08 20:32
211 查看
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:\>
相关文章推荐
- LEETCODE-Power of Two
- lintcode-子集17
- Maven 发布jar包到远程仓库
- [转载] 《祖谷物语》影评
- 360电话面试
- java下socket传文件
- Android中滑屏实现----手把手教你如何实现触摸滑屏以及Scroller类详解
- hdu 3853 LOOPS(概率 dp 期望)
- JAVA 第二个程序
- 2.24
- HDU 3549【网络流入门--然而我还是XXX】
- bzoj-1502 月下柠檬树
- 新RSS reader
- Linux Shell编程(3):数组
- Ignatius and the Princess III 1028 (母函数)
- 有效降低内存峰值防止过高及其原理分析
- C++11系列学习之六-----for
- 【英语】Bingo口语笔记(72) - play系列
- HDU4403-模拟、数学
- android开启远程调试