| 
				
				
					|  |  
					|  |  
					
				 
					|  |  
					|   |  
					|  |  
					|  |  
					|  |  
					|  |  
					|  |  
					|  |  
					|  |  
					|  |  
					|  |  
					| 
							
								| 6만원 이상 무료배송 |  
								|  |  
								| 주문하시는 총상품금액의 합계가
 6만원 이상일 경우
 택배비가 무료입니다.
 |  |  
					|  |  
					|  |  |  | 
	
		|  |  
		|  |  
		|  
				
					| [JAVA] 디렉토리 복사 예제(java.io) |  |  
		|  |  
		|  
				
					| 작성자: 
						
							어라
						
						  
						
							작성일: 2009-07-07 09:55  
						
						조회: 17396  
						댓글: 0 |  |  
		|  |  
		| 
				
					| import java.io.File; import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
 public class CopyDir {
 public static void copyDirectory(File sourcelocation , File targetdirectory)
 throws IOException {
 //디렉토리인 경우
 if (sourcelocation.isDirectory()) {
 //복사될 Directory가 없으면 만듭니다.
 if (!targetdirectory.exists()) {
 targetdirectory.mkdir();
 }
 
 String[] children = sourcelocation.list();
 for (int i=0; i<children.length; i++) {
 copyDirectory(new File(sourcelocation, children[i]),
 new File(targetdirectory, children[i]));
 }
 } else {
 //파일인 경우
 InputStream in = new FileInputStream(sourcelocation);
 OutputStream out = new FileOutputStream(targetdirectory);
 
 // Copy the bits from instream to outstream
 byte[] buf = new byte[1024];
 int len;
 while ((len = in.read(buf)) > 0) {
 out.write(buf, 0, len);
 }
 in.close();
 out.close();
 }
 }
 
 public static void main(String[] args) throws IOException {
 //c:\LOG의 내용을 c:\Temp에 복사 합니다.
 File source = new File("c:\\LOG");
 File target = new File("c:\\Temp");
 
 copyDirectory(source , target);
 }
 
 }
 
 
 |  |  
		|  |  
		|  |  
		|  |  
		| * 관련 댓글 한말씀 부탁합니다. |  
		|  |  |