상세 컨텐츠

본문 제목

[입출력] 스트림으로 파일 복사

자바

by esoesmio 2023. 4. 10. 21:16

본문

import java.io.*;

public class z15 {

    public static void main(String[] args) {
///카피해서 두는 방법


for(int i=0;i<100;i++) {
    String originfilenm = "/Users/eunsukkim/Downloads/1.jpeg";
    String copyFilename = "/Users/eunsukkim/Downloads/1" + i + "cop2y.jpeg";

    try {

        InputStream is = new FileInputStream(originfilenm);


        OutputStream os = new FileOutputStream(copyFilename);

//            byte[] readdata = new byte[1024];
//
//            while(true){
//
//                int cnt = is.read(readdata);
//
//                if(cnt == -1){
//                    break;
//                }
//
//           os.write(readdata);
//
//            }

        is.transferTo(os);

        os.flush();
        is.close();
        os.close();


    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (IOException io) {
        System.out.println(io.getMessage());
    }


}
















    }

}

관련글 더보기

댓글 영역