大家好,又见面了,我是全栈君。
学习Io操作(3),javaIo文件的复制!
package com.dufy.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
/**
*
* 练习IO操作 third <br/>
* 代码是写出来的,不是看出来的,我是阿飞-aflyun <br/>
* 在路上!
* @author aflyun
* @email 742981086@qq.com
*
*/
public class TestThirdIo {
/**
* 文件复制
* 基本思路还是从一个文件中读入内容,边读边写入另一个文件,就是这么简单
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String sou = "E:" + File.separator +"aflyun.txt";
String dir = "E:" + File.separator +"aflyundir.txt";
File file1=new File(sou);
File file2=new File(dir);
if(!file1.exists()){
System.out.println("被复制的文件不存在");
System.exit(1);
}
InputStream input=new FileInputStream(file1);
OutputStream output=new FileOutputStream(file2);
if((input!=null)&&(output!=null)){
int temp=0;
while((temp=input.read())!=(-1)){
output.write(temp);
}
}
input.close();
output.close();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/121267.html原文链接:https://javaforall.net
