class Program
{
static void Main(string[] args)
{
// FileStream
// 写
#region Writebyte
//using (FileStream fWriter = new FileStream("txt.txt", FileMode.Create, FileAccess.Write))
//{
////
//// fWriter.WriteByte(97);
//string s = Console.ReadLine();
//// byte[] bs = Encoding.Default.GetBytes(s);
//// ff fe
//fWriter.WriteByte(255);
//fWriter.WriteByte(254);
//byte[] bs = Encoding.Unicode.GetBytes(s);
//for (int i = 0;
i < bs.Length;
i++)
//{
//fWriter.WriteByte(bs[i]);
//}//}
#endregion#region Write
//using (FileStream fWriter = new FileStream("txt.txt", FileMode.Create, FileAccess.Write))
//{
////abc019AB
//byte[] bs = { 97, 98, 99, 48, 49, 57, 65, 66 };
//fWriter.Write(bs, 1, bs.Length - 1);
//}
#endregion// 读
#region ReadByte
//using (FileStream fReader = new FileStream("txt.txt", FileMode.Open, FileAccess.Read))
//{
//// bc019AB
////int i1 = fReader.ReadByte();
////int i2 = fReader.ReadByte();
////int i3 = fReader.ReadByte();
////int i4 = fReader.ReadByte();
////int i5 = fReader.ReadByte();
////int i6 = fReader.ReadByte();
////int i7 = fReader.ReadByte();
////int i8 = fReader.ReadByte();
//List list = new List();
//int res = -1;
//while ((res = fReader.ReadByte()) != -1)
//{
//list.Add((byte)res);
//}
//}
#endregion#region Read
//using (FileStream fReader = new FileStream("txt.txt", FileMode.Open, FileAccess.Read))
//{
//// 用数组来存储一个块字节
//// byte[] bs = new byte[1024 * 1024];
// 迅雷是不是有一个缓存//byte[] bs = new byte[10];
//int count = fReader.Read(bs, 1, bs.Length-1);
// 要求读取10个字节,从数组bs的第0个位置开始存储//}
#endregion// 使用FileStream读取文本文件,注意里面有汉字// 复制
Console.Write("请输入要复制的文件#");
string fileSource = Console.ReadLine();
if (!File.Exists(fileSource))
{
Console.WriteLine("文件不存在,请按任意键结束");
Console.ReadKey();
return;
}// 存在
Console.Write("请输入保存的路径名#");
string fileSave = Console.ReadLine();
using (FileStream fileReader = new FileStream(fileSource, FileMode.Open, FileAccess.Read))
{
using (FileStream fileWriter = new FileStream(fileSave, FileMode.Create, FileAccess.Write))
{
// 字节处理,作死
//int res = -1;
//while ((res = fileReader.ReadByte()) != -1)
//{
//fileWriter.WriteByte((byte)res);
//}// 字节数组
byte[] bs = new byte[1024 * 1024 * 10];
int count = 0;
while ((count = fileReader.Read(bs, 0, bs.Length)) > 0)
{
fileWriter.Write(bs, 0, count);
}}
}Console.WriteLine("OK");
Console.ReadKey();
}
}
【C#|C#文件流FileStream】
推荐阅读
- 圆的体积表面积和和字符型变量
- CPU底层|【CPU底层那些事(数组和指针真的一样吗()】)
- C#上位机|C#上位机(定时器计数)
- linux|GNU ARM 汇编指令(转)
- Linux|Linux下ARM汇编教程
- C#/VB.NET|C#/VB.NET 将Html转为Excel
- Java基础~无间断巩固|java基础-宇宙第一YWM(入门java--基础框图)
- java|秒杀项目(二)之验证功能&&全局共享&&参数解析器
- java|Mysql必知必会