本文给出使用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. Leetcode Unique Binary Search Trees

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  2. bzoj 1217 [HNOI2003]消防局的设立 Label:图论

    题目描述 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料,人类只修建了n-1条道路来连接这些基地,并且每两个基地都能够通过道路到达,所以所有的基地形成了一个巨大的树状 ...

  3. 51Nod 1046 A^B Mod C Label:快速幂

    给出3个正整数A B C,求A^B Mod C.   例如,3 5 8,3^5 Mod 8 = 3. Input 3个正整数A B C,中间用空格分隔.(1 <= A,B,C <= 10^ ...

  4. [知识点]Tarjan算法

    // 此博文为迁移而来,写于2015年4月14日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxnx.html UPD ...

  5. 【BZOJ】1856: [Scoi2010]字符串

    http://www.lydsy.com/JudgeOnline/problem.php?id=1856 题意:把n个1和m个0组成字符串,要求在组成的字符串中,任意的前k个字符1的个数不能少于0的个 ...

  6. 淘宝前端工程师:国内WEB前端开发十日谈

    一直想写这篇"十日谈",聊聊我对Web前端开发的体会,顺便解答下周围不少人的困惑和迷惘.我不打算聊太多技术,我想,通过技术的历练,得到的反思应当更重要. 我一直认为自己是" ...

  7. [LintCode] Maximal Square 最大正方形

    Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...

  8. List相关知识点.......课堂加整理

    package lis0924; //接口List(列表) import java.util.ArrayList; import java.util.Iterator; import java.uti ...

  9. ssh框架开发问题

    Struts + spring MVC + hibernate   6.1   从职责上分为表示层.业务逻辑层.数据持久层和域模块层四层. 其中使用Struts作为系统的整体基础架构,负责MVC的分离 ...

  10. jquery ui dialog去掉右上角的叉号

    var dialog = $("#id").dialog({ resizable:false, height:, width:, zIndex:, modal:true, open ...