Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- somefile = new URL("http://somefile.rar");
- ReadableByteChannel rbc = Channels.newChannel(somefile.openStream());
- FileOutputStream fos = new FileOutputStream("test");
- long start = System.currentTimeMillis();
- fos.getChannel().transferFrom(rbc, 0, 1 << 24);
- long end = System.currentTimeMillis();
- System.out.println(end-start);
- URL url = new URL("http://yourfile.rar");
- File target = new File("package.rar");
- try (BufferedInputStream bis = new BufferedInputStream(url.openStream())) {
- try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target))) {
- byte[] buffer = new byte[4096];
- int bytesRead;
- while ((bytesRead = bis.read(buffer)) != -1) {
- bos.write(buffer, 0, bytesRead);
- }
- bos.flush();
- }
- }
- IOUtils.copy(new BufferedInputStream(somefile.openStream()),
- new BufferedOutputStream(fos));
- // of course, you'd have to close the streams at the end.
- FileUtils.copyUrlToFile(URL url, String destination);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement