(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link.
(This post is part of my Visual Studio 2010 series)
Stream.CopyTo() is a new method added to System.IO.Stream in .Net framework 4, which allows you to copy bytes from one stream to another easily and makes your code simple.[more]
FileStream sourceStream = new FileStream(@"G:\test\art.bmp", FileMode.Open); FileStream targetStream = new FileStream(@"G:\test\art-copy.bmp", FileMode.CreateNew); sourceStream.CopyTo(targetStream); targetStream.Close(); sourceStream.Close();
This method is also available in MemoryStream(any subclass of System.IO.Stream).
This is a notable method if you especially do more file IO in your application, you may also look at your old code for chances to refactor it with this method(if you have time 🙂
-
Subscribe to the feed! (?) and receive any such future posts on your favorite feed reader
- Any comments? write here..