本文给出使用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. HTTPS, SPDY和 HTTP/2性能的简单对比

    中文原文:HTTPS, SPDY和 HTTP/2性能的简单对比 整理自:A Simple Performance Comparison of HTTPS, SPDY and HTTP/2 请尊重版权, ...

  2. [深入浅出WP8.1(Runtime)]文本块(TextBlock)

    4.3 文本块(TextBlock) 文本块(TextBlock)控件是用于显示少量文本的轻量控件,可以通过TextBlock呈现只读的文本,你可以把TextBlock控件理解为一种纯文本的展示控件. ...

  3. POJ 1654 Area(水题)

    题目链接 卡了一下精度和内存. #include <cstdio> #include <cstring> #include <string> #include &l ...

  4. GridView合并表头、多重表头(转)

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { switch (e.Row.RowType) ...

  5. winform让子窗体始终居于父窗体的中间

    实例: FormMsg msg = new FormMsg(); msg.TopMost = True; msg.StarPosition = FormStarPosition.Centerparen ...

  6. 如何将maven项目导入MyEclipse

    一.安装maven第一步:下载一个免安装版的apache-maven-3.0.3.zip解压后,配置环境变量 新建M2_HOME:   在path后面添加  %M2_HOME%\bin;   第二步: ...

  7. PHP 操作MySQL———来自copy

    学习要点:1.PHP 连接到MySQL2.增删改查3.其他常用函数 如果你已经具有了使用PHP.SQL 和MySQL 的丰富经验,现在就可以把所有这些技术组合在一起.PHP 与MySQL 之间稳固的集 ...

  8. nodeType的返回

    <p id="one" title="one_one">one_one_one</p> 1.用getElementById var o ...

  9. SPFA导读及介绍(转载)

    适用范围:给定的图存在负权边,这时类似Dijkstra等算法便没有了用武之地,而Bellman-Ford算法的复杂度又过高,SPFA算法便派上用场了. 我们约定有向加权图G不存在负权回路,即最短路径一 ...

  10. js 获取中文的拼音

    es6 + 模块化封装 "use strict"; module.exports = { //参数,中文字符串 //返回值:拼音首字母串数组 makePy (str) { if ( ...