본문 바로가기
java

[Java] 파일복사

by 호랭형님 2021. 10. 21.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {
	public static void main(String[] args) {
		String file_path = "원본파일경로";
		String copy_path = "복사된 파일 경로";

		try {
			FileInputStream input = new FileInputStream(new File(file_path));
			FileOutputStream output = new FileOutputStream(new File(copy_path));

			byte[] buf = new byte[1024];
			int readData;
			while((readData = input.read(buf))>0) {
				output.write(buf, 0, readData);
			}
			input.close();
			output.close();


		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

 

원본문서를 다른 폴더로 복사해야 될 일이 있어서 작성해본 코드입니다.

잘못된 부분이 있거나 더 좋은 코드 있으면 알려주세요~

'java' 카테고리의 다른 글

[Java] 폴더 내 파일 수 확인  (0) 2021.10.23
[Java]파일 사이즈  (0) 2021.10.23
[Java] 자바 정규식  (0) 2021.10.21
VO타입 list로 받기  (0) 2020.07.14
txt파일 한줄씩 읽기  (0) 2020.07.14

댓글