fileName이 복사할 대상 파일이고 newFileName이 복사되어 새롭게 생성될 파일명입니다. 근데 좀 살펴볼게… 실제 데이터를 복사(전송) 시키는 12번 코드의 transfer 함수는 실제로 전송된 바이트 수를 반환합니다. 전송하고자 하는 바이트수와 실제로 전송된 바이트 수 사이에 차이가 있을 수 있다는 건데.. 이 부분에 대한 고민을 좀 더 해봐야할 코드입니다.
try {
File inFile = new File(fileName);
FileInputStream inputStream = new FileInputStream(inFile);
File outFile = new File(newFileName);
FileOutputStream outputStream = new FileOutputStream(outFile);
FileChannel fcin = inputStream.getChannel();
FileChannel fcout = outputStream.getChannel();
long size = fcin.size();
fcin.transferTo(0, size, fcout);
fcout.close();
fcin.close();
outputStream.close();
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
