Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- dbms
- Login
- Tomcat
- 브라우저
- 알고리즘
- @Scheduled
- db
- mysql
- FCM
- ua-parser
- 물리적주소
- Java
- URLRewirte
- 접근장치
- 암호화
- 개발자도구
- eGov
- TailMe
- JEUS
- web server
- programmers
- Oracle
- window10
- scheduled
- WINDOW11
- AES
- WebtoB
- User-Agent
- Firebase
- Was
Archives
- Today
- Total
HD
URL로 첨부파일 다운로드 본문
반응형
- 최근 DB Migration 중에 URL로 첨부파일을 땡겨오기 위해서 구현한 로직
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HttpsURLConnection;
/**
* @Class Name : httpdownload.java
* @Description : http, https URL 첨부파일 다운
* @Modification Information
* @author HD
* @version 1.0
* @see
*
*/
public class httpdownload {
/**
* http, https URL 첨부파일 다운
* @param httpUrl 다운받을 URL
* @param downPath 다운받을 local path
* @param downName 다운파일명
*/
public static void httpDown(String httpUrl, String downPath, String downName) {
FileOutputStream fos = null;
InputStream is = null;
try {
//디렉토리 체크
File file = new File(downPath);
if (!file.exists()) {
file.mkdirs();
}
fos = new FileOutputStream(downPath+downName);
System.out.println("httpUrl = "+httpUrl);
URL url = new URL(httpUrl);
URLConnection urlConnection = url.openConnection();
//https
//HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
is = urlConnection.getInputStream();
byte[] buffer = new byte[1024];
int readBytes;
while ((readBytes = is.read(buffer)) != -1) {
fos.write(buffer, 0, readBytes);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
if (is != null) {
is.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
반응형
'JAVA' 카테고리의 다른 글
중복로그인 처리(feat.전자정부) (0) | 2022.01.25 |
---|---|
[구글 OTP] java (4) | 2021.09.14 |
이클립스 invalid LOC header 에러발생시 (0) | 2021.05.26 |
JAVA DB Connection (feat. mysql, oracle) (0) | 2020.12.28 |
PHP 직렬화 -> JAVA 데이터 변환 (feat.pherialize-1.2.4.jar) (0) | 2020.12.28 |
Comments