package com.tjetc.practice;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
File file = new File("e:/1.txt");
File file2 = new File("e:/2.txt");
if(!file2.exists()){
try {
file2.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(file);
fos = new FileOutputStream(file2);
//读取数据
byte[] buf = new byte[(int) file.length()];
fis.read(buf);
//写入数据
fos.write(buf);
System.out.println("复制完成!!!");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
//关闭流
fos.close();
fis.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}