package meganetpo.picturehandler;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;
public class HttpDownloader {
public void urlDownload(URL FromUrl, File ToFile) throws FileNotFoundException, IOException {
//ToFile.deleteOnExit();
//ToFile.createNewFile();
ReadableByteChannel bc = Channels.newChannel(FromUrl.openStream());
FileChannel fc = (new FileOutputStream(ToFile)).getChannel();
int pos = 0;// ������� � �����
int transferunit = 1024;// ����� ������������ �� 1024 ����
int len;// ������� ������������ �� ����� ����
while ((len = (int) fc.transferFrom(bc, (long) pos, (long) transferunit)) == transferunit) {
pos += len;
}
bc.close();
fc.close();
}
}