使用Java字节流拷贝文件
本文给出使用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字节流拷贝文件的更多相关文章
- [JAVA]字节流拷贝文件
import java.io.*; public class CopyFile { public static void main(String[] args) { //1.创建源 File in = ...
- Java字节流实现文件夹的拷贝
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...
- Java 字节流实现文件读写操作(InputStream-OutputStream)
Java 字节流实现文件读写操作(InputStream-OutputStream) 备注:字节流比字符流底层,但是效率底下. 字符流地址:http://pengyan5945.iteye.com/b ...
- JAVA字节流(读写文件)
InputStream此抽象类是表示字节输入流的所有类的超类.需要定义 InputStream 的子类的应用程序必须始终提供返回下一个输入字节的方法. int available()返回此输入流方法的 ...
- [JAVA]使用字节流拷贝文件
import java.io.*; /** * @Description: * @projectName:JavaTest * @see:PACKAGE_NAME * @author:郑晓龙 * @c ...
- IO之4种字节流拷贝文件方式对比
public class CopyMp4Demo { public static void main(String[] args) throws IOException { long start = ...
- java字节流复制文件
import java.io.FileInputStream; import java.io.FileOutputStream; import org.junit.Test; public class ...
- java——io、字节流缓冲区拷贝文件、字节缓冲流
使用try catch finally关闭文件流: 写入文件: import java.io.*; public class exp{ public static void main(String[] ...
- Java IO编程——文件拷贝
在操作系统里面有一个copy命令,这个命令的主要功能是可以实现文件的拷贝处理,现在要求模拟这个命令,通过初始化参数输入拷贝的源文件路径与拷贝的目标路径实现文件的拷贝处理. 需求分析: ·需要实现文件的 ...
随机推荐
- input type=checkbox checked disabled
input type=checkbox checked disabled 禁用无法提交!
- WPF standard ComboBox Items Source Change Issue
Today I encountered an issue with the WPF standard CombBox where if the bound ItemsSource (collectio ...
- 5分钟windows wamp php安装phpunit 2015最新安装实践
16:11 2015/11/235分钟windows wamp php安装phpunit 2015最新安装实践我花了一个下午和一个上午的时间注意:步骤中添加环境变量多的时候要保存很多步,知道窗口都自动 ...
- 【CodeVS】 p1225 八数码难题
题目描述 Description Yours和zero在研究A*启发式算法.拿到一道经典的A*问题,但是他们不会做,请你帮他们.问题描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字 ...
- tshark (wireshark)笔记
1. dumpcap -i eth0 -q -n -b duration:120 -b files:5000 -s65535 -f "! ip broadcast and ! ip mult ...
- 【MongoDB】2014-07-25T11:00:48.634+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:10061 由于目标计算机积极拒绝,无法连接。
1:启动MongoDB 2014-07-25T11:00:48.634+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errn ...
- HTML5 Input 类型
浏览器支持 Input type IE Firefox Opera Chrome Safari email No 4.0 9.0 10.0 No url No 4.0 9.0 10.0 No numb ...
- web前端开发CSS命名规范参考
做为一个web前端工程师,每天接触HTML.css就像吃饭一样,但是作为一名合作.优秀的web前端工程师,对DIV+CSS命名还是有一定的规范的,本文整理了一份web前端开发中DIV+CSS各种命名规 ...
- javascrpt 中的Ajax请求
回顾下javascript中的Ajax请求,写一个小例子: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...
- 4s使用iOS 8的一些真實感受
iPhone永遠離不開史上手機的爭論!你是否也在用呢? 今年iPhone 6/6Plus的發佈和上市可以說是振奮人心,大螢幕的升級.圓潤的外觀改變.全新的iOS 8系統,都是極具吸引力的.作為一名互聯 ...