2011. 10. 17. 16:51
void downloadData(String addr){
StringBuilder html = new StringBuilder();
try{
URL url = new URL(addr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
if(conn != null){
conn.setConnectTimeout(10000);
conn.setUseCaches(false);
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
File book=new File("/sdcard/filedir", "filename.dat");
FileOutputStream fileOutput = new FileOutputStream(book);
InputStream inputStream = conn.getInputStream();
int downloadedSize = 0;
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ( (bufferLength = inputStream.read(buffer)) > 0 ) {
fileOutput.write(buffer, 0, bufferLength);
downloadedSize += bufferLength;
}
fileOutput.close();
}
}
}catch(Exception ex){;}
}
안녕하세요 ^^
잠시 설명을 해볼까 합니다ㅎ
파일다운받을때 http방식으로 다운받는 로직인데요.
addr에 파일 풀경로를 넣어주시고
노란색으로 표시된부분에 다운받을실 경로와 파일명을 기입해주시면
끗!
도움이 되셨길 빌어요 ^^
즐코딩! 낫빡침!
'Programming > Android' 카테고리의 다른 글
Android - Unzip (0) | 2011.10.17 |
---|---|
Android - Down file using FTP/FTP방식으로 파일 다운 (0) | 2011.10.17 |
Android - Methods GET and POST in HTML forms//http전송 get방식, post방식 (0) | 2011.10.17 |
Android - keyboard setting for when layout is hidden by keyboard popup / EditText 클릭시 UI 같이 올라가는 문제 (0) | 2011.10.17 |
Android - custom button pressed image change (0) | 2011.10.12 |