using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; //添加命名空间
using System.IO; namespace 文件流
{
class Program
{
static void Main(string[] args)
{
string source = @"C:\Users\Administrator\Desktop\增加.gif"; string target = @"C:\Users\Administrator\Desktop\new.gif"; Command.CopyFile(source, target); Console.WriteLine("复制成功!"); Console.ReadKey();
}
} //操作类
public class Command
{
public static void CopyFile(string source, string target)
{
//创建读取流
using(FileStream fsRead = new FileStream(source, FileMode.Open, FileAccess.Read))
{
//创建写入流
using(FileStream fsWrite = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
{
//字节数组,存放取出的字节数
byte[] buffer = new byte[ * * ]; //循环,当i!=0的时候循环
while (true)
{
//当前是假存到字节数组中的字节数
int i = fsRead.Read(buffer, , buffer.Length); //如果i==0,break;
if (i == )
{
break;
} //写入数据
fsWrite.Write(buffer, , i);
}
}
}
}
}
}

FileStream -- 复制文件的更多相关文章

  1. Filestream复制视频文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  2. FileStream大文件复制

    FileStream缓冲读取和写入可以提高性能.FileStream读取文件的时候,是先讲流放入内存,经Flash()方法后将内存中(缓冲中)的数据写入文件.如果文件非常大,势必消耗性能.特封装在Fi ...

  3. C# FileStream复制大文件

    即每次复制文件的一小段,以节省总内存开销.当然,本机复制也可以采用.NET内部的System.IO.File.Copy方法. 本文转载:http://www.cnblogs.com/wolf-sun/ ...

  4. [转载]FileStream读写文件

    FileStream读写文件 FileStream类:操作字节的,可以操作任何的文件 StreamReader类和StreamWriter类:操作字符的,只能操作文本文件. 1.FileStream类 ...

  5. C# 压缩 解压 复制文件夹,文件的操作

    命名空间:namespace System.IO.Compression 压缩: //目标文件夹 string fileDirPath = "/Downloads/试题" + us ...

  6. FileStream读写文件【StreamWriter 和 StreamReader】

    FileStream对象表示在磁盘或网络路径上指向文件的流.这个类提供了在文件中读写字节的方法,但经常使用StreamReader或StreamWriter执行这些功能.这是因为FileStream类 ...

  7. Linux 远程复制文件

    Linux 远程复制文件 如果想把机器A上面的dir目录下面的所有文件复制到机器B的dir目录下,我们可以使用nc命令来完成 在机器A的dir目录下面执行: tar -czf - * | nc -l ...

  8. 复制文件的问题:使用FileInputStream和FileOutputStream实现文件复制

    public class Test{ public static void main(String [] args) { Test t=new Test(); t.upload(); } public ...

  9. JAVA实现复制文件夹

    package com.filetest; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; impor ...

随机推荐

  1. windos下安装PEAR 注意

    1.在这里下载PEAR http://pear.php.net/go-pear.phar 在页面右键另存为 go-pear.phar 到PHP的根目录,并去目录查看是否保存为了go-pear.phar ...

  2. Ants (POJ 1852)

    题目描述: Description An army of ants walk on a horizontal pole of length l cm, each with a constant spe ...

  3. java 语法 java没学好,休想学好安卓!

    int...a 里面的...表示可变参数,也就是说这是一个长度不定的数组 instanceof : instanceof关键字用于判断一个引用类型变量所指向的对象是否是一个类(或接口.抽象类.父类)的 ...

  4. JavaEE Tutorials (5) - 运行企业bean示例

    5.1cart示例56 5.1.1业务接口57 5.1.2会话bean类57 5.1.3@Remove方法61 5.1.4辅助类61 5.1.5运行cart示例615.2一个单例会话bean示例:co ...

  5. VC中TRACE()的用法

    个人总结:最近看网络编程是碰到了TRACE语句,不知道在哪里输出,查了一晚上资料也没找出来,今天终于在CSDN上找到了,真是个高地方啊,方法如下: 1.在MFC中加入TRACE语句 2.在TOOLS- ...

  6. iOS学习之NSAttributedString(富文本)

    NSAttributedString 叫做富文本,是一种带有属性的字符串,通过它可以轻松的在一个字符串中表现出多种字体.字号.字体大小等各不相同的风格,还可以对段落进行格式化,一般都是对可变富文本(N ...

  7. oracle误删的表恢复

    flashback table lip_organization to before drop;

  8. [Swust OJ 234]--IrreducibleNumber(题意太坑)

    题目链接:http://acm.swust.edu.cn/problem/0234/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  9. iOS8模拟器键盘弹不出来

    command + k  或 command + shift + k  切换到模拟器键盘 其默认是Mac键盘

  10. 调用opencv打开不摄像头

    调用opencv打开不摄像头,可以试试下面的语句: CvCapture* pCapture = cvCreateCameraCapture(0); 参数设为0 ,而不是-1,在自己电脑上可以 .