Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- System.out.println("Downloading: " + url);
- URL file = new URL(url);
- int size = file.openConnection().getContentLength();
- String path = "/Users/user/Downloads/test_download";
- String fileName = url.substring(url.lastIndexOf("/")+1);
- path = path + fileName;
- ReadableByteChannel in = Channels.newChannel(file.openStream());
- SeekableByteChannel out = Files.newByteChannel(Paths.get(fileName), WRITE, TRUNCATE_EXISTING, CREATE);
- ByteBuffer buf = ByteBuffer.allocate(size);
- threadName = fileName;
- System.out.println("Size: " + size + ";" + Paths.get(fileName) + "; " + Thread.currentThread().getName());
- while (in.read(buf) != -1) {
- buf.flip();
- out.write(buf);
- buf.rewind();
- buf.limit(buf.capacity());
- }
- in.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement