也就是 一个固定文件 在项目里面
现在要把他用程序来保存在一个 自定义的路径下
要求如果有同名的文件 也不理 直接复盖掉原文件高手们请赐教、、、、新人问题见笑了!界面越简单 也就是一个 选择文件的对话窗
openFileDialog然后 一个 确定 按钮一点确定 就把内部指定的文件保存并复盖在到选择好的路径下在线等!
现在要把他用程序来保存在一个 自定义的路径下
要求如果有同名的文件 也不理 直接复盖掉原文件高手们请赐教、、、、新人问题见笑了!界面越简单 也就是一个 选择文件的对话窗
openFileDialog然后 一个 确定 按钮一点确定 就把内部指定的文件保存并复盖在到选择好的路径下在线等!
解决方案 »
- ◆请大家帮忙看看,关于缓存的疑问◆
- C# agent 精灵 宠物
- winform 中 tabControl 的 选项卡排列问题
- 这样的问题居然没人回答上:radiobuttonlist如何绑定图片
- 请问windows mobile上如何实现程序的专机专用,求!!
- WPF相关 popup里的textbox不能输中文
- 请教我能不能看到asp.net网页啊?
- 请问怎么用程序写一个圆形或者方形甚至异形的按钮?
- C# 中接口如何实现?
- c#的自定义用户控件为什么在.NET环境中的VC下的工具箱中不能显示
- 请问SQL2000如何将'1,2,3,4' 链接其他表得到'AAA,BBB,CCC,DDD'
- 用datagridview显示数据库数据的问题
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
private void button3_Click(object sender, EventArgs e)
{
//定义一个文件流,用于读取原文件
FileStream fs = new FileStream(this.textBox1 .Text ,FileMode.Open );
//定义内存缓冲区
byte []buffer=new byte [(int)fs.Length ];
//将文件读入到内存缓冲区中
fs.Read(buffer ,0,buffer .Length );
fs.Close();
//定义一个文件流,用于将缓冲区中的文件流写入文件
FileStream fs1 = new FileStream(this.textBox2 .Text ,FileMode.Create );
//写入文件
fs1.Write(buffer ,0,buffer .Length );
fs1.Close();
}
大文件拷贝方法:
private void CopyFile(string fromFile, string toFile, int lengthEachTime)
{
FileStream fileToCopy = new FileStream(fromFile, FileMode.Open, FileAccess.Read);
FileStream copyToFile = new FileStream(toFile, FileMode.Append, FileAccess.Write);
int lengthToCopy;
if (lengthEachTime < fileToCopy.Length)//如果分段拷贝,即每次拷贝内容小于文件总长度
{
byte[] buffer = new byte[lengthEachTime];
int copied = 0;
while (copied <= ((int)fileToCopy.Length - lengthEachTime))//拷贝主体部分
{
lengthToCopy = fileToCopy.Read(buffer, 0, lengthEachTime);
fileToCopy.Flush();
copyToFile.Write(buffer, 0, lengthEachTime);
copyToFile.Flush();
copyToFile.Position = fileToCopy.Position;
copied += lengthToCopy;
}
int left = (int)fileToCopy.Length - copied;//拷贝剩余部分
lengthToCopy = fileToCopy.Read(buffer, 0, left);
fileToCopy.Flush();
copyToFile.Write(buffer, 0, left);
copyToFile.Flush();
}
else//如果整体拷贝,即每次拷贝内容大于文件总长度
{
byte[] buffer = new byte[fileToCopy.Length];
fileToCopy.Read(buffer,0,(int)fileToCopy.Length);
fileToCopy.Flush();
copyToFile.Write(buffer, 0, (int)fileToCopy.Length);
copyToFile.Flush();
}
fileToCopy.Close();
copyToFile.Close();
}
{
File.Copy(sourceFile/*源文件*/, targetFile/*目标文件*/, true);
}
catch (Exception ex)
{
MessageBox.Show("文件操作失败: " + ex.Message);
}