본문 바로가기

IT개발일지/Android

[Android] 다운로드 URL을 이용하여 파일 다운로드하기

public File fileEmptyPDF(final String downloadURL) {
final File resultFile = new File(Cvalue._DOWNLOAD_FOLDER, downloadURL.substring(downloadURL.lastIndexOf("/") + 1).replace(".pdf", "_edit.pdf"));
try {
resultFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Thread thread = new Thread() {
public void run() {
FileDownloader.downloadFile(downloadURL, resultFile);
}
};
thread.start();

while (true) {
if (thread.isAlive()) {
try {
Thread.currentThread().sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
//Log.d(CommonUtil.TAG, "예외처리");
}
} else {
break;
}
}

//Log.d(CommonUtil.TAG, "빈서식지 : " + resultFile);
return resultFile;
}


안드로이드 개발중 파일을 다운로드 해야하는 상황이 생겼다.


다운로드 URL을 이용하여 파일을 다운로드 하는 방법이다.


필자는 pdf 파일을 다운 받기 때문에 pdf 형식의 파일을 다운로드 하는 방법을 사용하였다.