Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. memoryStream.WriteTo(fileStream);
  2.  
  3. fileStream.CopyTo(memoryStream);
  4. memoryStream.CopyTo(fileStream);
  5.  
  6. using (FileStream file = new FileStream("file.bin", FileMode.Create, System.IO.FileAccess.Write)) {
  7. byte[] bytes = new byte[ms.Length];
  8. ms.Read(bytes, 0, (int)ms.Length);
  9. file.Write(bytes, 0, bytes.Length);
  10. ms.Close();
  11. }
  12.  
  13. using (MemoryStream ms = new MemoryStream())
  14. using (FileStream file = new FileStream("file.bin", FileMode.Open, FileAccess.Read)) {
  15. byte[] bytes = new byte[file.Length];
  16. file.Read(bytes, 0, (int)file.Length);
  17. ms.Write(bytes, 0, (int)file.Length);
  18. }
  19.  
  20. using (FileStream file = new FileStream("file.bin", FileMode.Create, FileAccess.Write)) {
  21. memoryStream.WriteTo(file);
  22. }
  23.  
  24. using (FileStream file = new FileStream("file.bin", FileMode.Open, FileAccess.Read)) {
  25. byte[] bytes = new byte[file.Length];
  26. file.Read(bytes, 0, (int)file.Length);
  27. ms.Write(bytes, 0, (int)file.Length);
  28. }
  29.  
  30. MemoryStream ms = new MemoryStream(bytes, writable: false);
  31.  
  32. byte[] testData = new byte[] { 104, 105, 121, 97 };
  33. var ms = new MemoryStream(testData, 0, 4, false, true);
  34. Assert.AreSame(testData, ms.GetBuffer());
  35.  
  36. MemoryStream ms = new MemoryStream();
  37. FileStream file = new FileStream("file.bin", FileMode.Create, FileAccess.Write);
  38. ms.WriteTo(file);
  39. file.Close();
  40. ms.Close();
  41.  
  42. MemoryStream ms = new MemoryStream();
  43. using (FileStream fs = File.OpenRead(file))
  44. {
  45. fs.CopyTo(ms);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement