Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter06 : FileCopy 본문

JAVA/chapter24_io

chapter06 : FileCopy

GAWON 2023. 5. 31. 09:22
package org.joonzis.ex;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Ex06_FileCopy {
	public static void main(String[] args)throws IOException {
  
		File file = new File("cat.jpg");
		if(file.exists()) {
			BufferedInputStream bis =
					new BufferedInputStream(new FileInputStream(file));
			
			//복사본 생성
			BufferedOutputStream bos =
					new BufferedOutputStream(new FileOutputStream("cat2.jpg"));
			
			byte[] buffer = new byte[1024];
			
			long start = System.currentTimeMillis();
			while(bis.read(buffer)!=-1) {
				bos.write(buffer);
			}
			long end = System.currentTimeMillis();
			System.out.println("복사 시간 : " +(end - start)+ "밀리초");
			
			//File 클래스 사용으로 인한 사용 가능한 메소드
			System.out.println("파일명 : " + file.getName());
			System.out.println("파일명 : " + file.getName());
			System.out.println("파일명 : " + file.getName());
		}
		
	}
}

'JAVA > chapter24_io' 카테고리의 다른 글

Test . io  (0) 2023.05.31
chapter05 : FileCopy  (0) 2023.05.31
chapter04 : FileInput  (0) 2023.05.31
chapter03 : FileOutput  (0) 2023.05.31
chapter02 : FileInput  (0) 2023.05.31