Notice
Recent Posts
Recent Comments
Link
관리 메뉴

왕초보 코딩 개발 일지 블로그

[23.06.01] 예제 13-7 : 바이너리 파일 복사 (이미지 파일 복사하기) 본문

Java/예제

[23.06.01] 예제 13-7 : 바이너리 파일 복사 (이미지 파일 복사하기)

아캔두우잇 2023. 6. 1. 12:26
반응형
package j20230601;

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

public class BinaryCopy {

	public static void main(String[] args) {
		File src = new File( ".\\resource\\iu.jpg");
		File dest = new File(".\\resource\\myiu.jpg");
		int c;
		try {
			FileInputStream fi = new FileInputStream(src);
			FileOutputStream fo = new FileOutputStream(dest);
			while((c = fi.read()) != -1) {
				fo.write((byte)c);
			}
			fi.close();
			fo.close();
			System.out.println( src.getPath()+ "를 " + dest.getPath()+
		"로 복사하였습니다.");
		} catch (IOException e) {
			System.out.println("파일 복사 오류");
		}
	}
}

 ".\\resource\\iu.jpg"

resource 폴더에 iu.jpg 이미지 파일을 먼저 넣어두고 시작해야 한다. 

짠 이미지 파일 복사 완료!

반응형