Java URL Copy copy(URL fromUrl, File toFile)

Here you can find the source of copy(URL fromUrl, File toFile)

Description

copy

License

Open Source License

Declaration

public static void copy(URL fromUrl, File toFile) throws IOException 

Method Source Code


//package com.java2s;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;

public class Main {
    public static void copy(URL fromUrl, File toFile) throws IOException {
        InputStream in = null;//w  ww .  j ava2  s.  com
        OutputStream out = null;
        try {
            in = fromUrl.openStream();
            out = new FileOutputStream(toFile);
            byte[] bytes = new byte[16384];
            while (true) {
                int bytesRead = in.read(bytes);
                if (bytesRead < 0)
                    break;

                out.write(bytes, 0, bytesRead);
            }
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (IOException e) {
                }
            if (out != null)
                try {
                    out.close();
                } catch (IOException e) {
                }
        }
    }
}

Related

  1. copy(URL in, File out)
  2. copy(URL source, String destination)
  3. copy_url_to_file(String url, String filename)
  4. copyFile(URL url, String destFilePath)