posted by Solver Full-stack Developer 2011.07.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){;}
}
신고

티스토리 툴바