본문 바로가기

백엔드

Java File copy with append if exits file


import org.apache.commons.io.IOUtils;

private void copy(File source, File target){
		try {
			in = new FileInputStream(source);
			out = new FileOutputStream(target, true);
		
        	IOUtils.copy(in, out);
        	
        } catch (IOException ex) {
        	ex.printStackTrace();
        	
        } finally {
        	IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }
}

FileOutputStream의 생성자 중 두번째 인자는 append 여부.