package kimoji;

import java.io.*;

public class FileTest {

public static void main(String[] args) throws IOException {
out1("D:\\ppt\\Oracle_SQL基礎知識.ppt", "aaa.ppt");
out2("D:\\ppt\\Oracle_SQL基礎知識.ppt", "aaa1.ppt");
out3("D:\\ppt\\Oracle_SQL基礎知識.ppt", "aaa11.ppt");
out4("D:\\ppt\\Oracle_SQL基礎知識.ppt", "aaa111.ppt");

/*if (file.exists() && file.isDirectory()) {
String names[] = file.list();
for (String name : names) {
System.out.println(name);
}
System.out.println("000000000000000000000000000000000000000000000000000000000000000000000000");
String[] nameNei = file.list(new FilenameFilter() {

@Override
public boolean accept(File dir, String name) {
return name.endsWith(".java");
}
});
for (String string : nameNei) {
System.out.println(string);
}
}*/

}

/**
* 一次读取一个字节
* @param src1 :读取路径
* @param src2 :写入路径
* @throws IOException
*/
public static void out1(String src1,String src2) throws IOException{
FileInputStream fileInputStream = new FileInputStream(src1);
FileOutputStream fOutputStream = new FileOutputStream(src2);
int len = -1;
Long star = System.currentTimeMillis();
while((len = fileInputStream.read())!=-1){
fOutputStream.write(len);
}
long end = System.currentTimeMillis();
System.out.println("out1耗时为:"+(end-star)+"毫秒");
fileInputStream.close();
fOutputStream.close();
}

/**
* 一次读取一个字节数组
* @param str1:读取路径
* @param str2:写入路径
* @throws IOException
*/
public static void out2(String str1,String str2) throws IOException{
FileInputStream fis = new FileInputStream(str1);
FileOutputStream fos = new FileOutputStream(str2);
int len = -1;
byte temp [] = new byte[1024];
Long star = System.currentTimeMillis();
while((len = fis.read())!=-1){
fos.write(temp, 0, len);
}
long end = System.currentTimeMillis();
System.out.println("out2耗时为:"+(end-star)+"毫秒");
fis.close();
fos.close();
}
/**
* 带有缓冲区的一次读取一个字节
* @param src1 :读取路径
* @param src2 :写入路径
* @throws IOException
*/
public static void out3(String str1,String str2) throws IOException{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(str1));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(str2));
int len = -1;
Long star = System.currentTimeMillis();
while((len=bis.read())!=-1){
bos.write(len);
}
Long end = System.currentTimeMillis();
System.out.println("out3共耗时"+(end-star)+"毫秒");
bis.close();
bos.close();
}
public static void out4(String str1,String str2) throws IOException{
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(str1));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(str2));
int len = -1;
byte [] temp = new byte[1024];
Long star = System.currentTimeMillis();
while((len = bis.read())!=-1){
bos.write(temp, 0, len);
}
Long end = System.currentTimeMillis();
System.out.println("out4共耗时"+(end-star)+"毫秒");
bis.close();
bos.close();
}
}

用韵结果如下:

out1耗时为:6431毫秒
out2耗时为:6223毫秒
out3共耗时28毫秒
out4共耗时197毫秒

java通过IO流复制文件的更多相关文章

  1. Java I/O流 复制文件速度对比

    Java I/O流 复制文件速度对比 首先来说明如何使用Java的IO流实现文件的复制: 第一步肯定是要获取文件 这里使用字节流,一会我们会对视频进行复制(视频为非文本文件,故使用之) FileInp ...

  2. Java基础 IO流的文件和目录的五类主要操作

    笔记: /** IO流的 文件和目录的操作 * 1.路径需要 需要两个反斜杠 或者一个单斜杠! * 绝对路径:包括盘符在内的完整的路径名! * 相对路径:在当前目录文件下的路径! * 2.File 是 ...

  3. java基础IO流 复制键盘录入的目录,复制其中的.java文件到指定目录,指定目录中有重名,则改名 对加密文件计算字母个数

    package com.swift.jinji; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; im ...

  4. IO流 复制文件及文件夹

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

  5. Java基础IO流 ,文件读取,由易至难

    最基础的读取文件 import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;imp ...

  6. java用字符io流复制文件

    一.小文件一次快速读写 import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExceptio ...

  7. JAVA(IO流)文件复制

    package com.am; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOEx ...

  8. java中使用IO流复制文件

    public class TestIO { public static void main(String[] args) { // TODO Auto-generated method stub tr ...

  9. java 输入输出IO流 RandomAccessFile文件的任意文件指针位置地方来读写数据

    RandomAccessFile的介绍: RandomAccessFile是Java输入输出流体系中功能最丰富的文件内容访问类,它提供了众多的方法来访问文件内容,它既可以读取文件内容,也可以向文件输出 ...

随机推荐

  1. Android碎笔录3——点击跳转

    只要是view都能设置点击事件,不必要非得是Button. 要想实现跳转得三步走: 第一步.绑定 每个Layout都有一个一个java文件跟它绑定,这个Layout相关的代码都写在这个java文件里 ...

  2. (Stanford CS224d) Deep Learning and NLP课程笔记(一):Deep NLP

    Stanford大学在2015年开设了一门Deep Learning for Natural Language Processing的课程,广受好评.并在2016年春季再次开课.我将开始这门课程的学习 ...

  3. 【转】c++ http下载文件

    #include <afx.h> #include <afxinet.h> #define RECVPACK_SIZE 2048 bool DownloadSaveFiles( ...

  4. python 待关注库

    Python待关注库 GUI 图形 Tkinter/wxPython/PyGTK/PyQt/PySide Web框架 django/web2py/flask/bottle/tornadoweb/web ...

  5. 关于v$rowcache

    关于v$rowcache column parameter format a21column pct_succ_gets format 999.9column updates format 999,9 ...

  6. windows 下 gdb 的安装

    在 windows 下 gcc/g++ 的安装 这篇文章中已经提到,用MinGW Installation Manager可以方便地管理 MinGW 组件,因此使用该软件安装 gdb . 打开 Min ...

  7. Django路由系统---django重点之url映射分发

    django重点之url映射分发 在全局项目的urls.py中进行子项目的映射,然后在子项目中创建一个urls.py去处理自己项目中的请求,同时也实现了代码的解耦 添加路由分发的原则[全局urls.p ...

  8. Asp.Net MVC Identity 2.2.1 使用技巧(一)

    开发环境:vs2015 UP3  or  vs2017RC  项目环境:asp.net 4.6.1   identity版本为:asp.net identity 2.2.1 1.创建项目. 没什么好说 ...

  9. .net framework profiles /.net framework 配置

    几年前一篇关于 .net framework client profile http://www.cnblogs.com/zzj8704/archive/2010/05/19/1739130.html ...

  10. 如何高效的写出markdown笔记

    重置用户名和密码 安利一个小工具donet-cnblog可以同步图片到cnblog中,同时生成对应的Markdown笔记.写博客的时候我们可以本地写,用这个工具同步到cnblog上能够大大节省我们的时 ...