java通过IO流复制文件
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流复制文件的更多相关文章
- Java I/O流 复制文件速度对比
Java I/O流 复制文件速度对比 首先来说明如何使用Java的IO流实现文件的复制: 第一步肯定是要获取文件 这里使用字节流,一会我们会对视频进行复制(视频为非文本文件,故使用之) FileInp ...
- Java基础 IO流的文件和目录的五类主要操作
笔记: /** IO流的 文件和目录的操作 * 1.路径需要 需要两个反斜杠 或者一个单斜杠! * 绝对路径:包括盘符在内的完整的路径名! * 相对路径:在当前目录文件下的路径! * 2.File 是 ...
- java基础IO流 复制键盘录入的目录,复制其中的.java文件到指定目录,指定目录中有重名,则改名 对加密文件计算字母个数
package com.swift.jinji; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; im ...
- IO流 复制文件及文件夹
package io; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; im ...
- Java基础IO流 ,文件读取,由易至难
最基础的读取文件 import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;imp ...
- java用字符io流复制文件
一.小文件一次快速读写 import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExceptio ...
- JAVA(IO流)文件复制
package com.am; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOEx ...
- java中使用IO流复制文件
public class TestIO { public static void main(String[] args) { // TODO Auto-generated method stub tr ...
- java 输入输出IO流 RandomAccessFile文件的任意文件指针位置地方来读写数据
RandomAccessFile的介绍: RandomAccessFile是Java输入输出流体系中功能最丰富的文件内容访问类,它提供了众多的方法来访问文件内容,它既可以读取文件内容,也可以向文件输出 ...
随机推荐
- sql-pivot
PIVOT PIVOT运算符用于在列和行之间进行数据旋转或透视转换,同时执行聚合运算 ,,) Order By empid asc Select * From ( Select empid,YEAR( ...
- vuex入门教程和思考 [转] 里面有几个实例
Vuex基础概念 vuex中涉及的概念主要有下面几点,下面做个简单的介绍和理解. Vuex 官方文档:https://vuex.vuejs.org/zh-cn/ 官网有介绍,也有个demo shopp ...
- System.Media.Color与System.Drawing.Color转换方法
public static System.Media.Color GetMediaColorFromDrawingColor(System.Drawing.Color color) { re ...
- VS2013下使用log4cplus
原文:http://blog.csdn.net/qq_35850668/article/details/52522932 最近工作需要,需要使用log库来完善日志类记录,由于之前没什么经验,遇到了很多 ...
- Spring IOC (DI-依赖注入)
看到一篇文章,讲Spring的依赖注入讲的很好理解,也很容易理解,非常详细.原文地址: https://blog.csdn.net/javazejian/article/details/5456130 ...
- restful知识点之三restframework认证-->权限-->频率
认证.权限.频率是层层递进的关系 权限业务时认证+权限 频率业务时:认证+权限+频率 局部认证方式 from django.conf.urls import url,include from djan ...
- pmp证书
- plsql连接12cR2 PDB报错ORA-28040/ORA-01017
http://hbxztc.blog.51cto.com/1587495/1907533 PS: 在数据库服务器上的oracle/network/admin/sqlnet.ora文件添加一行SQLNE ...
- 并发集合 System.Collections.Concurrent 命名空间
System.Collections.Concurrent 命名空间提供多个线程安全集合类. 当有多个线程并发访问集合时,应使用这些类代替 System.Collections 和 System.Co ...
- 树-二叉搜索树-AVL树
树-二叉搜索树-AVL树 树 树的基本概念 节点的度:节点的儿子数 树的度:Max{节点的度} 节点的高度:节点到各叶节点的最大路径长度 树的高度:根节点的高度 节点的深度(层数):根节点到该节点的路 ...