本文给出使用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. NOIp 2014 #1 生活大爆炸版石头剪刀布 Label:模拟

    题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 集中出现了一种石头剪刀布的升级版游戏. 升级版游戏在传统的 ...

  2. 摘:JavaScript性能优化小知识总结

    原文地址:http://www.codeceo.com/article/javascript-performance-tips.html JavaScript的性能问题不容小觑,这就需要我们开发人员在 ...

  3. 【BZOJ1677】[Usaco2005 Jan]Sumsets 求和 递推

    ... #include <iostream> using namespace std; ]; int n,i; int main() { cin>>n; f[]=; ;i&l ...

  4. ThinkPHP3.2.3--Linux服务器首页文件index.php路径配置问题

    在windows服务器环境下,可以define ('SITE_URL','http://192.168.1.101/'); 但上传到linux服务器环境下不能正常解析,可使用相对路径:define ( ...

  5. Redis_master-slave模式

    类似mysql的master-slave模式一样,redis的master-slave可以提升系统的可用性,master节点写入cache后,会自动同步到slave上. 环境: master node ...

  6. 转 Datatables中文API——基本参数

    鉴于自己一直在使用datatables,发现这是个很不错的表格插件,但是好的东西都是英文的,所以我结合自己的使用经验,把官网的英文api做下简单的翻译,同时也希望大家把自己的使用经验一起分享出来,让我 ...

  7. Func<T>与Action<T>委托泛型介绍:转

    .Net 3.5之后,微软推出了Func<T>与Action<T>泛型委托.进一步简化了委托的定义. Action<T>委托主要的表现形式如下: public de ...

  8. MVVMLight Messenging

    Basically there are two possible ways to send a message, first using an overload of the RaisePropert ...

  9. python中的进程、线程(threading、multiprocessing、Queue、subprocess)

    Python中的进程与线程 学习知识,我们不但要知其然,还是知其所以然.你做到了你就比别人NB. 我们先了解一下什么是进程和线程. 进程与线程的历史 我们都知道计算机是由硬件和软件组成的.硬件中的CP ...

  10. event事件学习小节

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...