使用工具类
import IODemo_02.CopyUtils;
import org.junit.Test;
public class AppTest {
@Test
public void CopyTest(){
CopyUtils. copyFile("F:/桌面/aaq.jpg","E:/TestDemo/ccc.jpg");
}
}
工具类
public class CopyUtils {
public static void copyFile(String src,String des){
FileInputStream fis = null;
BufferedInputStream bis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try{
bis = new BufferedInputStream(new FileInputStream(src));
bos = new BufferedOutputStream(new FileOutputStream(des));
int temp = 0;
while ((temp = bis.read())!=-1){
bos.write(temp);
}
bos.flush();
}catch (Exception e){
e.printStackTrace();
}finally {
try{
if (bis != null)
bis.close();
if (fis != null)
fis.close();
if (bos != null)
bos.close();
if (fos !=null)
fos.close();
}catch (Exception e){
e.printStackTrace();
}
}
}
}