2014-11-11 4 views

답변

0

이 시도 :

private static void downloadFile(String url, String filePath) { 
    try { 
     File outputFile = new File(filePath); 
     URL u = new URL(url); 
     URLConnection conn = u.openConnection(); 
     int contentLength = conn.getContentLength(); 

     DataInputStream stream = new DataInputStream(u.openStream()); 

     byte[] buffer = new byte[contentLength]; 
     stream.readFully(buffer); 
     stream.close(); 

     DataOutputStream fos = new DataOutputStream(new FileOutputStream(outputFile)); 
     fos.write(buffer); 
     fos.flush(); 
     fos.close(); 
    } catch(FileNotFoundException e) { 
     return; // swallow a 404 
    } catch (IOException e) { 
     return; // swallow a 404 
    } 
} 

this answer에서 적응.

관련 문제