C# IO流的操作非常重要,我们读写文件都会使用到这个技术,这里先演示一个文件内容复制的例子,简要说明C#中的IO操作。
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//将文件内容读到流中
Stream stream = File.Open("test.txt", FileMode.OpenOrCreate);
//初始化一个字节数组
byte[] bytes = new byte[(int)stream.Length];
//将流读到字节数组中
stream.Read(bytes, 0, bytes.Length);
//用MemoryStream接收
MemoryStream ms = new MemoryStream(bytes);
//从开始处设置
ms.Seek(0, SeekOrigin.Begin);
//再把返回的MemoryStr