Java Utililty Methods URL Load

List of utility methods to do URL Load

Description

The list of methods to do URL Load are organized into topic(s).

Method

StringloadFile(String url)
Load a text file into a String
try {
    return loadFile(new URL(url));
} catch (MalformedURLException e) {
    e.printStackTrace();
    return null;
byte[]loadFile(URL resource)
Load the content from the URL into a byte array.
InputStream is = resource.openStream();
try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int n;
    while ((n = is.read(buffer)) > 0) {
        bos.write(buffer, 0, n);
    return bos.toByteArray();
} finally {
    is.close();
FileloadFile(URL url)
load File
return loadFile(url, "");
ArrayListloadFileNoArray(URL f)
load File No Array
ArrayList<String> temp = new ArrayList<>();
BufferedReader br;
try {
    br = new BufferedReader(new InputStreamReader(f.openStream()));
    String strLine;
    while ((strLine = br.readLine()) != null) {
        if (strLine.equals(""))
            continue;
...
ListloadFileOrUrlToList(String iFileOrUrl)
Reads text from EITHER a remote URL (that starts with http://) OR a local file (doesn't start with http://), into a list of strings, each containing one line of the file.
return iFileOrUrl.startsWith("http://") ? loadUrlToList(new URL(iFileOrUrl))
        : loadFileToList(new File(iFileOrUrl));
StringloadFromUrl(String url)
load From Url
StringBuffer sb = new StringBuffer();
URL u = new URL(url);
InputStream in = u.openStream();
byte[] buf = new byte[1024];
try {
    while (true) {
        int n = in.read(buf);
        sb.append(new String(buf, 0, n));
...
byte[]loadFromURL(URL url)
load From URL
InputStream is = null;
try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    is = url.openStream();
    int r;
    byte[] buffer = new byte[8000];
    while ((r = is.read(buffer)) >= 0) {
        if (r == 0)
...
StringloadFromURL(URL url)
load From URL
if (url == null) {
    return null;
try {
    InputStreamReader reader = new InputStreamReader(url.openStream());
    StringBuilder sb = new StringBuilder();
    char[] buf = new char[4096];
    int read;
...
PropertiesloadFromURL(URL url)
load From URL
Properties result = new Properties();
InputStream is = null;
try {
    is = url.openStream();
    result.load(is);
} finally {
    if (is != null) {
        is.close();
...
StringloadFully(URL url)
load Fully
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int l;
InputStream is = url.openStream();
try {
    while ((l = is.read(buf)) >= 0) {
        baos.write(buf, 0, l);
} finally {
    is.close();
return baos.toString();