classProgram {Static voidMain (string[] args) { //Create a path to downloadWebRequest req = WebRequest.Create ("Http://static.cnblogs.com/images/adminlogo.gif"); //respond to picture information using(WebResponse res =req. GetResponse ())//get the picture stream using(Stream instream =Res. GetResponseStream ())//Copy to local path using(Stream OutStream =NewFileStream (@"C:\users\administrator\desktop\c#oop Practice \2.png", FileMode.Create)) {Copy (instream, OutStream); } Console.WriteLine ("copy done!"); } //encapsulating the Copy method Static voidCopy (Stream instream, stream OutStream,intSize) { byte[]bytes =New byte[Size]; intLen =0; while(len = instream.read (Bytes,0, bytes. Length)) >0) {outstream.write (bytes,0, Len); } } //Copy method overloading Static voidcopy (Stream instream,stream outstream) {copy (Instream,outstream,1024x768*1024x768); } }
CopyTo: File Copy method
classProgram {Static voidMain (string[] args) { //Create a path to downloadWebRequest req = WebRequest.Create ("Http://static.cnblogs.com/images/adminlogo.gif"); //respond to picture information using(WebResponse res =req. GetResponse ())//get the picture stream using(Stream instream =Res. GetResponseStream ())//Copy to local path using(Stream OutStream =NewFileStream (@"C:\users\administrator\desktop\c#oop Practice \2.png", FileMode.Create)) {Instream.copyto (OutStream); } Console.WriteLine ("copy done!"); } //encapsulating the Copy method Static voidCopy (Stream instream, stream OutStream,intSize) { byte[]bytes =New byte[Size]; intLen =0; while(len = instream.read (Bytes,0, bytes. Length)) >0) {outstream.write (bytes,0, Len); } } //Copy method overloading Static voidcopy (Stream instream,stream outstream) {copy (Instream,outstream,1024x768*1024x768); } }
c#--Simple File Downloader