C#自学31—file类的使用方法,使用File类操作文件的数据

class Program
    {
        static void Main(string[] args)
        {

            //创建一个文件
            //File.Create(@"C:\Users\SpringRain\Desktop\new.txt");
            //Console.WriteLine("创建成功");
            //Console.ReadKey();

            //删除一个文件
            //File.Delete(@"C:\Users\SpringRain\Desktop\new.txt");
            //Console.WriteLine("删除成功");
            //Console.ReadKey();
            //1024byte=1kb
            //1024kb=1M
            //1024M=1G
            //1024G=1T
            //1024T=1PT

            //复制一个文件
            //File.Copy(@"C:\Users\SpringRain\Desktop\code.txt", @"C:\Users\SpringRain\Desktop\new.txt");
            //Console.WriteLine("复制成功");
            //Console.ReadKey();


            //剪切
            File.Move(@"C:\Users\SpringRain\Desktop\code.txt", @"C:\Users\SpringRain\Desktop\newnew.txt");
            Console.WriteLine("剪切成功");
            Console.ReadKey();


            //Console.WriteLine(sizeof(char));
            //Console.ReadKey();
            //Console.WriteLine(sizeof(string));a  "dsfdsfds"
            //Console.ReadKey();
        }
    }
class Program
    {
        static void Main(string[] args)
        {
            //byte[] buffer = File.ReadAllBytes(@"C:\Users\SpringRain\Desktop\1.txt");


            //EncodingInfo[] en = Encoding.GetEncodings();
            //foreach (var item in en)
            //{
            //    Console.WriteLine(item.DisplayName);
            //}
            //Console.ReadKey();
            //将字节数组转换成字符串
            //string s = Encoding.UTF8.GetString(buffer);
            //Console.WriteLine(s);
            // Console.WriteLine(buffer.ToString());
            //编码格式:指的就是你以怎样的形式来存储字符串
            //a-z 0-9  Ascii  117 u---->汉字--->GB2312 GBK
            //int n = (int)'u';
            //char c = (char)188;
            //Console.WriteLine(c);
            Console.WriteLine(n);


            //string s="今天天气好晴朗,处处好风光";
            将字符串转换成字节数组
            //byte[] buffer=  Encoding.Default.GetBytes(s);
            以字节的形式向计算机中写入文本文件
            //File.WriteAllBytes(@"C:\Users\SpringRain\Desktop\1.txt", buffer);
            //Console.WriteLine("写入成功");
            //Console.ReadKey();


            //使用File类来实现一个多媒体文件的复制操作

            //读取
            byte[] buffer = File.ReadAllBytes(@"C:\Users\SpringRain\Desktop\12333.wmv");
            Console.ReadKey();

            写入
            //File.WriteAllBytes(@"C:\Users\SpringRain\Desktop\new.wav", buffer);
            //Console.WriteLine("复制成功");
            //Console.ReadKey();


            //byte[] buffer=new byte[1024*1024*5];
            //while (true)
            //{
            //    File.WriteAllBytes(@"C:\Users\SpringRain\Desktop\123.wmv", buffer);
            //}

        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值