本文给出使用Java字节流实现文件拷贝的例子

package LearnJava;

import java.io.*;

public class FileTest {

    public static void main(String args[]) throws Exception{

        if(args.length != 2) {
System.exit(1); //如果参数个数不够,退出程序
} File infile = new File(args[0]);
File outfile = new File(args[1]); if(!infile.exists()){
System.out.println(1);
System.exit(1); //如果源文件不存在,退出程序
} if(!outfile.getParentFile().exists()){
outfile.getParentFile().mkdirs(); //目标目录如果不存在,创建目录
} InputStream in = new FileInputStream(infile);
OutputStream out = new FileOutputStream(outfile); long start = System.currentTimeMillis(); byte[] data = new byte[10000];
int foot = 0;
while((foot = in.read(data)) != -1) {
out.write(data, 0, foot);
} long end = System.currentTimeMillis(); System.out.println("拷贝时间: "+(end - start));
in.close();
out.close();
}
}

使用Java字节流拷贝文件的更多相关文章

  1. [JAVA]字节流拷贝文件

    import java.io.*; public class CopyFile { public static void main(String[] args) { //1.创建源 File in = ...

  2. Java字节流实现文件夹的拷贝

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...

  3. Java 字节流实现文件读写操作(InputStream-OutputStream)

    Java 字节流实现文件读写操作(InputStream-OutputStream) 备注:字节流比字符流底层,但是效率底下. 字符流地址:http://pengyan5945.iteye.com/b ...

  4. JAVA字节流(读写文件)

    InputStream此抽象类是表示字节输入流的所有类的超类.需要定义 InputStream 的子类的应用程序必须始终提供返回下一个输入字节的方法. int available()返回此输入流方法的 ...

  5. [JAVA]使用字节流拷贝文件

    import java.io.*; /** * @Description: * @projectName:JavaTest * @see:PACKAGE_NAME * @author:郑晓龙 * @c ...

  6. IO之4种字节流拷贝文件方式对比

    public class CopyMp4Demo { public static void main(String[] args) throws IOException { long start = ...

  7. java字节流复制文件

    import java.io.FileInputStream; import java.io.FileOutputStream; import org.junit.Test; public class ...

  8. java——io、字节流缓冲区拷贝文件、字节缓冲流

    使用try catch finally关闭文件流: 写入文件: import java.io.*; public class exp{ public static void main(String[] ...

  9. Java IO编程——文件拷贝

    在操作系统里面有一个copy命令,这个命令的主要功能是可以实现文件的拷贝处理,现在要求模拟这个命令,通过初始化参数输入拷贝的源文件路径与拷贝的目标路径实现文件的拷贝处理. 需求分析: ·需要实现文件的 ...

随机推荐

  1. Codeforces Round #353 (Div. 2) A. Infinite Sequence

    Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its fi ...

  2. Codeforces Round #252 (Div. 2) A - Valera and Antique Items

    水题 #include <iostream> #include <set> #include <vector> #include <algorithm> ...

  3. 为什么用evernote

    其实是没有什么为什么的. 如果真要找个理由,那应该是: 为知的界面看着总觉得很糙.      这个糙指的是不像个好软件,而装上evernote感觉就不一样. 有道笔记新版本貌似在我这儿有BUG.    ...

  4. as3如何做出残影效果

    在页游中,时不时能看到人物做一些快速移动动作如冲刺时,有残影效果,强化了画面表现.实际人肉眼之所以能看到残影的效果,是因为观察到的物体会在人视线中残留几十毫秒时间,当运动物体运动太快时,人肉眼所见未能 ...

  5. iOS中JSONModel的使用

    iOS中JSONModel的使用   流弊的JSON数据模型框架 https://github.com/jsonmodel/jsonmodel 版本 1.3.0 如果你喜欢JSONModel,并且使用 ...

  6. Jfinal中手动提交/回滚 事物

    在Jfinal中有个Tx类为事物声明类 在方法或controller上面加@Before({Tx.class})即可,可是这样并不能满足有的业务场景 下面是今天写的手动提交的事物处理方法,希望对大家有 ...

  7. html5的本地存储

    转载1:http://www.cnblogs.com/fly_dragon/p/3946012.html 转载2:http://www.cnblogs.com/xiaowei0705/archive/ ...

  8. thinkphp条件查询和模糊查询的一些方法

    #文章管理 public function adminArticle(){ $adminArticle=M("article"); $arr_seach=$this->sea ...

  9. 数位DP HDU3555

    Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submi ...

  10. 2016HUAS暑假集训训练题 B - Catch That Cow

    B - Catch That Cow Description Farmer John has been informed of the location of a fugitive cow and w ...