package cn.hq.io;
import java.io.*;
public class Copy {
public static void main(String[] args) {
copy("123.txt", "123copy.txt");
}
public static void copy(String srcPath, String destPath) {
File src = new File(srcPath);
File dest = new File(destPath);
InputStream inputStream = null;
OutputStream outputStream = null;
try {
inputStream = new FileInputStream(src);
outputStream = new FileOutputStream(dest);
byte[] flush = new byte[1024];
int length = -1;
while ((length = inputStream.read(flush)) != -1) {
outputStream.write(flush, 0, length);
}
outputStream.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}