Guest User

Untitled

a guest
Jan 22nd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. public static void main(String[] args) throws Exception {
  2. String destDirectory = "C:\Users\test\text.zip";
  3. URL url = new URL("http://corpus.byu.edu/wikitext-samples/text.zip");
  4. downloadFile("http://corpus.byu.edu/wikitext-samples/text.zip", destDirectory);
  5.  
  6. }
  7.  
  8.  
  9. public static void downloadFile(String ZIP_FILE_URL, String INPUT_ZIP_FILE) {
  10. try {
  11. long startTime = System.currentTimeMillis();
  12.  
  13. URL url = new URL(ZIP_FILE_URL);
  14.  
  15. url.openConnection();
  16. InputStream reader = url.openStream();
  17.  
  18. FileOutputStream writer = new FileOutputStream(INPUT_ZIP_FILE);
  19. byte[] buffer = new byte[102400];
  20. int totalBytesRead = 0;
  21. int bytesRead = 0;
  22.  
  23. System.out.println("Reading ZIP file 20KB blocks at a time.n");
  24.  
  25. while ((bytesRead = reader.read(buffer)) > 0) {
  26. writer.write(buffer, 0, bytesRead);
  27. buffer = new byte[102400];
  28. totalBytesRead += bytesRead;
  29. }
  30.  
  31. long endTime = System.currentTimeMillis();
  32.  
  33. System.out.println("Done. " + new Integer(totalBytesRead).toString() + " bytes read (" + new Long(endTime - startTime).toString() + " millseconds).n");
  34. writer.close();
  35. reader.close();
  36. } catch (MalformedURLException e) {
  37. e.printStackTrace();
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
Add Comment
Please, Sign In to add comment