Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. somefile = new URL("http://somefile.rar");
  2. ReadableByteChannel rbc = Channels.newChannel(somefile.openStream());
  3. FileOutputStream fos = new FileOutputStream("test");
  4. long start = System.currentTimeMillis();
  5. fos.getChannel().transferFrom(rbc, 0, 1 << 24);
  6. long end = System.currentTimeMillis();
  7. System.out.println(end-start);
  8.  
  9. URL url = new URL("http://yourfile.rar");
  10. File target = new File("package.rar");
  11.  
  12. try (BufferedInputStream bis = new BufferedInputStream(url.openStream())) {
  13. try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target))) {
  14. byte[] buffer = new byte[4096];
  15. int bytesRead;
  16. while ((bytesRead = bis.read(buffer)) != -1) {
  17. bos.write(buffer, 0, bytesRead);
  18. }
  19. bos.flush();
  20. }
  21. }
  22.  
  23. IOUtils.copy(new BufferedInputStream(somefile.openStream()),
  24. new BufferedOutputStream(fos));
  25. // of course, you'd have to close the streams at the end.
  26.  
  27. FileUtils.copyUrlToFile(URL url, String destination);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement