Java URL Load readFromURL(URL url)

Here you can find the source of readFromURL(URL url)

Description

read From URL

License

Open Source License

Declaration

public static String readFromURL(URL url) throws IOException, UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2009, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://w  ww.  j  a  va  2 s .  co  m
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;

public class Main {
    public static String readFromURL(URL url) throws IOException, UnsupportedEncodingException {
        InputStream is = url.openStream();
        InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");
        StringBuffer buffer = new StringBuffer();
        char[] cbuf = new char[256];
        int len;
        do {
            len = inputStreamReader.read(cbuf);
            if (len > 0) {
                buffer.append(cbuf, 0, len);
            }
        } while (len >= 0);
        inputStreamReader.close();
        return buffer.toString();
    }
}

Related

  1. readFromFile(URL source)
  2. readFromUrl(String url)
  3. readFromUrl(String urlString)
  4. readFromUrl(String urlText)
  5. readFromUrl(URL url)
  6. readGOMappingFile(URL filename, Set secondAttributeList)
  7. readHttpBytes(String url)
  8. readHttpFile(final String urlStr)
  9. readInteger(URL src, int radix)

  10. HOME | Copyright © www.java2s.com 2016