Package meganetpo.picturehandler

Source Code of meganetpo.picturehandler.HttpDownloader

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();
    }
}
TOP

Related Classes of meganetpo.picturehandler.HttpDownloader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.