FileStream类操作

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace FileSetream类
{
    internal class Program
    {
        static void Main(string[] args)
        {
            #region  读取数据
            //实例化                       读取路径                                            如果没有该路径就创建  读取
            // FileStream fsRead = new FileStream(@"C:\Users\Administrator\Desktop\IO操作\111111.txt",FileMode.OpenOrCreate,FileAccess.Read);
            // //创建读取的解码的数组
            // byte[] buffer = new byte[1024*1024*5];
            返回本次实际读取到的有效字节
            // int r =fsRead.Read(buffer,0,buffer.Length);
            // //将字节数组中的每一个元素按照指定的编码格式解码成字符串
            // string s=Encoding.UTF8.GetString(buffer,0,r);
            // //关闭流
            // fsRead.Close();
            // //释放流所占用的资源
            // fsRead.Dispose();
            // Console.WriteLine(s);
            // Console.ReadKey();
            #endregion

            #region  写入数据
            using (FileStream fsWrite = new FileStream(@"C:\Users\Administrator\Desktop\IO操作\222222.txt", FileMode.OpenOrCreate, FileAccess.Write)) 
            {
                
                string str = "看我把你干掉1111";
                //定义编码
                byte[] buffer = Encoding.UTF8.GetBytes(str);
                //将位置赋值,使其追加
                fsWrite.Position = buffer.Length;
                fsWrite.Write(buffer, 0, buffer.Length);
                
            }
            Console.WriteLine("写入成功");
            Console.ReadKey();

            #endregion
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值