Java URL Load readNetFile(String urlstr)

Here you can find the source of readNetFile(String urlstr)

Description

read Net File

License

Open Source License

Declaration

public static final String readNetFile(String urlstr) 

Method Source Code

//package com.java2s;

import java.io.IOException;
import java.io.InputStream;

import java.net.URL;

public class Main {
    public static final String readNetFile(String urlstr) {
        InputStream in = null;/*w  w w.jav a2 s  .c om*/
        try {
            URL url = new URL(urlstr);
            in = url.openStream();
            String txt = readText(in);
            return new String(txt.getBytes("ISO-8859-1"), "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (Exception e) {
                }
        }
    }

    public static final String readText(InputStream in) throws IOException {
        if (in == null)
            return "";
        int c = -1;
        StringBuffer buffer = new StringBuffer();
        while ((c = in.read()) != -1)
            buffer.append((char) c);
        return buffer.toString();
    }
}

Related

  1. readLinesTrimmedNoCommentFromUrl(final URL fileUrl, final String commentString)
  2. readListFile(URL listFile)
  3. readListFile(URL listFile)
  4. readMappingFile(final URL filename)
  5. readModelFromUrl(URL file, Class clazz)
  6. readPage(final String urlStr)
  7. readPage(URL url)
  8. readProperties(final URL url)
  9. readProperties(final URL url)