实现文件拷贝的共轭能
来源:互联网 发布:郭德纲说网络 编辑:程序博客网 时间:2024/05/07 17:24
package iotest.javase.test;
import java.io.*;
public class testiocopye_04 {
public static void main(String[] args) throws IOException {
//如果要执行拷贝命令,则必须通过初始化参数传递源文件路径及目标文件路径
if (args.length !=2) {//参数内容必须是两个
System.out.println("错误的命令,请输入正确的命令");
System.exit(1);//退出程序
}
//如果现在有参数了。那么还要验证源文件是否存在
File infile = new File(args[0]);
if (!infile.exists()) {
System.out.println("路径错误,请输入源文件的正确路径。");
System.exit(1);
}
//如果拷贝的目标文件存在,则也不应该进行拷贝
File outfile=new File(args[1]);
if (outfile.exists()) {//目标文件已经存在
System.out.println("拷贝的路径已经窜在,请更换路径。");
System.exit(1);
}
long start = System.currentTimeMillis();
InputStream in= new FileInputStream(infile);
OutputStream out= new FileOutputStream(outfile);
copy(in,out);//实现文件拷贝
in.close();
out.close();
long end=System.currentTimeMillis();
System.out.println("拷贝的时间"+(end-start));//文件拷贝所需要用的时间
}
private static void copy(InputStream in, OutputStream out) throws IOException {
int temp = 0;//保存每次读取的字节量
while((temp = in.read()) !=-1){
out.write(temp);
}
}
}
import java.io.*;
public class testiocopye_04 {
public static void main(String[] args) throws IOException {
//如果要执行拷贝命令,则必须通过初始化参数传递源文件路径及目标文件路径
if (args.length !=2) {//参数内容必须是两个
System.out.println("错误的命令,请输入正确的命令");
System.exit(1);//退出程序
}
//如果现在有参数了。那么还要验证源文件是否存在
File infile = new File(args[0]);
if (!infile.exists()) {
System.out.println("路径错误,请输入源文件的正确路径。");
System.exit(1);
}
//如果拷贝的目标文件存在,则也不应该进行拷贝
File outfile=new File(args[1]);
if (outfile.exists()) {//目标文件已经存在
System.out.println("拷贝的路径已经窜在,请更换路径。");
System.exit(1);
}
long start = System.currentTimeMillis();
InputStream in= new FileInputStream(infile);
OutputStream out= new FileOutputStream(outfile);
copy(in,out);//实现文件拷贝
in.close();
out.close();
long end=System.currentTimeMillis();
System.out.println("拷贝的时间"+(end-start));//文件拷贝所需要用的时间
}
private static void copy(InputStream in, OutputStream out) throws IOException {
int temp = 0;//保存每次读取的字节量
while((temp = in.read()) !=-1){
out.write(temp);
}
}
}
阅读全文
0 0
- 实现文件拷贝的共轭能
- 文件拷贝的实现
- 如何能实现javabean的属性拷贝
- 如何实现文件的拷贝
- 文件拷贝功能的实现
- iOS 实现文件的拷贝
- JavaIO实现文件的拷贝
- 用java实现文件的拷贝
- 习题:用java实现文件的拷贝
- VC实现文件的拷贝移动
- C语言实现的文件拷贝
- 使用mmap实现文件的拷贝
- python 实现文件的递归拷贝-转
- 字符流实现文件数据的拷贝
- Java实现文件拷贝的方法
- 用python代码实现文件的拷贝
- JAVA-IO 文件拷贝功能的实现
- NIO方式实现文件的快速拷贝
- Eclipse tomcat插件配置使用
- The type javax.servlet.http.HttpServletRequest cannot be resolved
- 用自己的图片数据做tensorflow深度学习
- 全新勒索病毒爆发:一样的套路这次没人上当了
- 服务券兑换接口说明以及同步失败的分析和解决
- 实现文件拷贝的共轭能
- automake
- Xml文件的读取和插入学习
- ubuntu12.04 16.04 server下安装配置samba
- 剑指offer——二叉树中和为某一值得路径
- Spring Boot生成bean的二种方法
- matlab—同态滤波的实现
- Android 实现Button的5种方法
- Android之实用开发规范