当前位置:网站首页>[C # notes] use file stream to copy files
[C # notes] use file stream to copy files
2022-07-07 02:20:00 【Start()】
Namespace to be introduced : System.IO
C# A sealed copy of the file API:
System.IO.File.Copy(); // A copy of a document
System.IO.File.ReadAllBytes(); // Read all byte groups of the file
System.IO.File.WriteAllBytes(); // Write byte group to file
Next, I will do it myself , Use the way of reading and writing the file stream to copy the file , There are three main steps :
public string filePath = @"C:\Users\Njiyue\Desktop\ddd.jpg";
public string copyToPath = @"C:\Users\Njiyue\Desktop\ New folder \ccc.jpg";
private void Test()
{
#region First step : obtain Two files “ flow ”
FileInfo oneFileInfo = new FileInfo(filePath);
if (!File.Exists(copyToPath))
File.Create(copyToPath);// If there is no target file , Just create one
FileInfo twoFileInfo = new FileInfo(copyToPath);
FileStream fs1 = oneFileInfo.OpenRead();// Read the file , Convert file to byte file
FileStream fs2 = twoFileInfo.OpenWrite();// write file , Convert file to byte file
#endregion
#region The second step : Cyclic read write
byte[] buff = new byte[2048];// Read and write once 2048 Bytes
int contentLen = fs1.Read(buff, 0, 2048);// Read the file 2048 Bytes , And cache it to buff Byte group , Returns the read length , If the length is less than 2048, The description reads to the end , If it is equal to 0, It means that there are no bytes to read
// Loop read operation
while (contentLen != 0)
{
fs2.Write(buff, 0, contentLen); // Key method , Write the stream to
contentLen = fs1.Read(buff, 0, 2048);// Call once , Will be read in turn next 2048 byte
}
#endregion
#region The third step : Close the read-write process
// Turn off reading and writing , To avoid occupying files
fs1.Close();
fs2.Close();
fs1 = fs2 = null;
#endregion
}
边栏推荐
- ROS learning (21) robot slam function package -- installation and testing of orbslam
- Halcon实例转OpenCvSharp(C# OpenCV)实现--瓶口缺陷检测(附源码)
- Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
- The GPG keys listed for the "MySQL 8.0 community server" repository are already ins
- TiFlash 源码阅读(四)TiFlash DDL 模块设计及实现分析
- Analyze "C language" [advanced] paid knowledge [II]
- Halcon knowledge: segment_ contours_ XLD operator
- NPM install compilation times "cannot read properties of null (reading 'pickalgorithm')“
- FLIR blackfly s usb3 industrial camera: white balance setting method
- ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
猜你喜欢
Flir Blackfly S 工业相机:通过外部触发实现多摄像头同步拍摄
Time synchronization of livox lidar hardware -- PPS method
3D激光SLAM:Livox激光雷达硬件时间同步
[paper reading | deep reading] graphsage:inductive representation learning on large graphs
Cisp-pte practice explanation (II)
STM32F4---通用定时器更新中断
Schedulx v1.4.0 and SaaS versions are released, and you can experience the advanced functions of cost reduction and efficiency increase for free!
组合导航:中海达iNAV2产品描述及接口描述
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
随机推荐
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件
PostgreSQL图形化界面工具之pgAdmin4
RC振荡器和晶体振荡器简介
真实项目,用微信小程序开门编码实现(完结)
ROS learning (24) plugin
一片叶子两三万?植物消费爆火背后的“阳谋”
Date processing tool class dateutils (tool class 1)
ROS learning (XIX) robot slam function package cartographer
张平安:加快云上数字创新,共建产业智慧生态
STM32F4---通用定时器更新中断
投资的再思考
张平安:加快云上数字创新,共建产业智慧生态
ROS learning (25) rviz plugin
微服务架构介绍
Web开发小妙招:巧用ThreadLocal规避层层传值
2022 system integration project management engineer examination knowledge point: Mobile Internet
Several classes and functions that must be clarified when using Ceres to slam
STM32F4---PWM输出
Halcon knowledge: segment_ contours_ XLD operator
Time synchronization of livox lidar hardware -- PPS method