- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _15File类
- {
- 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();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace _16_使用File类操作文件的数据
- {
- 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);
- //}
- }
- }
- }