상세 컨텐츠

본문 제목

url을 통한 파일 다운로드

BackEnd/JAVA

by H_Develop 2023. 10. 4. 13:44

본문

try {
    FileOutputStream fos = new FileOutputStream("C:\\Users\\user\\Desktop\\HTY\\Copy3.pdf");
    is = conn.getInputStream();
    byte[] buffer = new byte[1024];
    int readBytes;

    while ((readBytes = is.read(buffer)) != -1) {

        fos.write(buffer, 0, readBytes);
    }
    fos.close();
    System.out.println("파일 다운완료");

} catch (Exception e) {
    e.printStackTrace();
}

FileOutputStream() 안에 다운로드 받을 위치를 지정해주면 된다.

파일 명까지 잡아주어야 한다.

 

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

StringBuffer StringBuilder  (0) 2023.02.23
isEmpty() String, Array  (0) 2023.02.22
JAVA Server - Client 서버 클라이언트 연결  (0) 2022.08.09
JAVA BufferedReader  (0) 2022.08.09
JAVA IO(Input/Output)  (0) 2022.08.09

관련글 더보기