Java URL Copy copyFromURL(final String query, final File target)

Here you can find the source of copyFromURL(final String query, final File target)

Description

copy data from URL to the target file

License

Open Source License

Declaration

public static void copyFromURL(final String query, final File target) 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 {
    /** copy data from URL to the target file **/
    public static void copyFromURL(final String query, final File target) throws IOException {
        final URL url = new URL(query);
        final InputStream in = url.openStream();
        final OutputStream fous = new FileOutputStream(target);
        final byte buff[] = new byte[0x3FF];
        int sz = 0;
        try {/*from w w  w  .  jav  a 2 s .  c  o m*/
            while ((sz = in.read(buff)) >= 0) {
                fous.write(buff, 0, sz);
            }
        } finally {
            fous.close();
        }
    }
}

Related

  1. copy(URL fromUrl, File toFile)
  2. copy(URL in, File out)
  3. copy(URL source, String destination)
  4. copy_url_to_file(String url, String filename)
  5. copyFile(URL url, String destFilePath)
  6. copyRemoteFile(URL url, File localFile)
  7. copyResource(URL from, File to)
  8. copyResource(URL resource, File destination)
  9. copyUrlBinaryFile(String fileName, String sourceUrlPath, String destPath)