android tech.

파일 복사해서 저장하기

zimamdero 2014. 5. 2. 15:08

public void copy(String originPath, String resultPath, String resultFileName) {

File origin = new File(originPath);

File resultDir = new File(resultPath);

resultDir.mkdirs();

File result = new File(resultPath + "/" + resultFileName);

FileInputStream input;

FileOutputStream output;

FileChannel originChanel;

FileChannel resultChanel;

try {

input = new FileInputStream(origin);

output = new FileOutputStream(result);

originChanel = input.getChannel();

resultChanel = output.getChannel();

originChanel.transferTo(0, originChanel.size(), resultChanel);

originChanel.close();

resultChanel.close();

input.close();

output.close();

} catch (Exception e) {

}

}


originPath - 원본 파일 경로 및 파일 이름

resultPath - 저장할 경로

resultFileName - 저장할 파일 이름