All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickntap.utils.URLUtils Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package com.clickntap.utils;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;

public class URLUtils {

    public static String getSource(String url, String charsetName) throws Exception {
        String source = null;
        InputStream in = new URL(url).openStream();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        IOUtils.copy(in, out);
        source = out.toString(charsetName);
        out.close();
        in.close();
        return source;
    }

    public static void download(String url, File file) throws Exception {
        InputStream in = new URL(url).openStream();
        FileOutputStream out = new FileOutputStream(file);
        IOUtils.copy(in, out);
        out.close();
        in.close();
    }

    public static String getSource(String url) throws Exception {
        return getSource(url, ConstUtils.UTF_8);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy