![将文件复制到指定路径[C# 文件操作].doc_第1页](http://file1.renrendoc.com/fileroot_temp2/2020-3/1/f2c7f237-7da7-473e-8434-90b7a72d9cdd/f2c7f237-7da7-473e-8434-90b7a72d9cdd1.gif)
![将文件复制到指定路径[C# 文件操作].doc_第2页](http://file1.renrendoc.com/fileroot_temp2/2020-3/1/f2c7f237-7da7-473e-8434-90b7a72d9cdd/f2c7f237-7da7-473e-8434-90b7a72d9cdd2.gif)
![将文件复制到指定路径[C# 文件操作].doc_第3页](http://file1.renrendoc.com/fileroot_temp2/2020-3/1/f2c7f237-7da7-473e-8434-90b7a72d9cdd/f2c7f237-7da7-473e-8434-90b7a72d9cdd3.gif)
![将文件复制到指定路径[C# 文件操作].doc_第4页](http://file1.renrendoc.com/fileroot_temp2/2020-3/1/f2c7f237-7da7-473e-8434-90b7a72d9cdd/f2c7f237-7da7-473e-8434-90b7a72d9cdd4.gif)
全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
将现有文件复制到新文件,不允许改写现有文件。C#public FileInfo CopyTo(string);将现有文件复制到新文件,允许改写现有文件。C#public FileInfo CopyTo(string, bool);C# 将文件复制到指定路径,允许改写同名的目标文件 COPYusing System;using System.IO;class Test public static void Main() string path = c:/temp/MyTest.txt; string path2 = path + temp; try / Create the file and clean up handles. using (FileStream fs = File.Create(path) / Ensure that the target does not exist. File.Delete(path2); / Copy the file. File.Copy(path, path2); Console.WriteLine(0 copied to 1, path, path2); / Try to copy the same file again, which should succeed. File.Copy(path, path2, true); Console.WriteLine(The second Copy operation succeeded, which was expected.); catch Console.WriteLine(Double copy is not allowed, which was not expected.); C# COPY TOusing System;using System.IO;class Test public static void Main() string path = c:/temp/MyTest.txt; string path2 = c:/temp/MyTest.txt + temp; FileInfo fi1 = new FileInfo(path); FileInfo fi2 = new FileInfo(path2); try / Create the file and clean up handles. using (FileStream fs = fi1.Create() /Ensure that the target does not exist. fi2.Delete(); /Copy the file. fi1.CopyTo(path2); Console.WriteLine(0 was copied to 1., path, path2); /Try to copy it again, which should succeed. fi1.CopyTo(path2, true); Console.WriteLine(The second Copy operation succeeded, which is expected.); catch Console.WriteLine(Double copying was not allowed, which is not expected.); 若要执行此操作.请参见本主题中的示例.创建文本文件。向文件写入文本写入文本文件。向文件写入文本读取文本文件。从文件读取文本向文件中追加文本。打开并附加到日志文件File.AppendTextFileInfo.AppendText重命名或移动文件。File.MoveFileInfo.MoveTo删除文件。File.DeleteFileInfo.Delete复制文件。File.CopyFileInfo.CopyTo获取文件大小。FileInfo.Length获取文件属性。File.GetAttributes设置文件属性。File.SetAttributes确定文件是否存在。File.Exists读取二进制文件。对刚创建的数据文件进行读取和写入写入二进制文件。对刚创建的数据文件进行读取和写入检索文件扩展名。Path.GetExtension检索文件的完全限定路径。Path.GetFullPath检索路径中的文件名和扩展名。Path.GetFileName更改文件扩展名。Path.ChangeExtensionProgress 类的使用private void CopyWithProgress(string filenames) / Display the ProgressBar control. pBar1.Visible = true; / Set Minimum to 1 to represent the first file being copied. pBar1.Minimum = 1; / Set Maximum to the total number of files to copy. pBar1.Maximum = filenames.Length; / Set the initial value of the ProgressBar. pBar1.Value = 1; / Set the Step property to a value of 1 to represent each filebeing copied. pBar1.Step = 1; / Loop through all files to copy. for (int x = 1; x = filenames.Length; x+) / Copy the file and increment the
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 区块链技术在2025年跨境支付跨境支付跨境支付平台用户行为分析报告
- 2025年特种设备安全操作员考试题库(安全技术)试题(附答案)
- 农业生物技术在种业中的应用2025年创新驱动与产业变革前瞻报告
- 2025年事业单位人员招聘笔试试题(附答案)
- 2025年学前教育师资队伍教师教学评价与反馈体系构建与完善报告
- 2024-2025学年度临床执业医师测试卷及参考答案详解(模拟题)
- 新能源行业光伏发电技术创新与环保效益分析报告
- 养老机构医养结合模式下的养老人才引进与培养机制研究报告
- 2025年中考数学总复习《因式分解》每日一练试卷及完整答案详解(各地真题)
- 2024-2025学年度法律职业资格考试高分题库附参考答案详解【轻巧夺冠】
- Unit+3+Fascinating+Parks+Reading+and+Thinking+导学案 高中英语人教版(2019)选择性必修第一册
- 2024至2030年中国银饰品市场需求分析及投资战略规划研究报告
- 医院环境卫生学监测和院感控制课件
- FURUNO 电子海图 完整题库
- YBT 165-2018 铝镁碳砖和镁铝碳砖
- 2024年惠州市国资本投资集团限公司招聘29人(高频重点提升专题训练)共500题附带答案详解
- 手卫生完整课件
- 北师大版小学数学三年级上册课时练习试题及答案(全册)
- 浙江水运交通工程安全管理台帐
- 《丰收欢乐而归》名师课件(简谱)
- 朗文3000词汇表大全
评论
0/150
提交评论