import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Practice01 {
public static void copyFile(String source , String target) {
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
try{
fileInputStream = new FileInputStream(source);
fileOutputStream = new FileOutputStream(target);
//通过字节去读取
int data = -1;
while((data = fileInputStream.read())>=0){
fileOutputStream.write(data);
}
}catch(IOException ioException){
ioException.printStackTrace();
}finally{
try {
fileInputStream.close();
}catch(IOException ioException){
ioException.printStackTrace();
}
try{
fileOutputStream.close();
}catch(IOException ioException){
ioException.printStackTrace();
}
}
}
}
public static void copyFileByArray(String source , String target) {
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
try{
fileInputStream = new FileInputStream(source);
fileOutputStream = new FileOutputStream(target);
//通过字节去读取
byte[] dataArray = new byte[1024];
int length = -1;
while((length = fileInputStream.read(dataArray))>=0){
fileOutputStream.write(dataArray,0,length);
}
}catch(IOException ioException){
ioException.printStackTrace();
}finally{
try {
fileInputStream.close();
}catch(IOException ioException){
ioException.printStackTrace();
}
try{
fileOutputStream.close();
}catch(IOException ioException){
ioException.printStackTrace();
}
}
}