2011. 7. 19. 15:07
void DownloadData(){
StringBuilder html = new StringBuilder();
try{
URL url = new URL("http://192.XXX.XXX.XXX/XXXXX");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setConnectTimeout(10000);
conn.setUseCaches(false);
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
File file = new File("/sdcard/", "filename.ZIP");
FileOutputStream fileOutput = new FileOutputStream(file);
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();
}
conn.disconnect();
}catch(Exception ex){;}
}
'Programming > Android' 카테고리의 다른 글
Android - Activity for result /자신을 호출한 엑티비티에게 데이터 보내기 (0) | 2011.07.28 |
---|---|
Android - Convert Raw file to OutStream / raw파일 outputstream으로 변경 (0) | 2011.07.20 |
Android - plugging Aptana in eclipe / 이클립스에서 aptana 사용하기 (0) | 2011.06.15 |
Android - to use json[JSONArray,JSONObject](example) /안드로이드에서 json 사용하기 (0) | 2011.06.15 |
Android - set pinch zoom in webview / 웹뷰에서 핀치 줌 설정 (0) | 2011.06.15 |