Java URL Connection getFromUrl(String url)

Here you can find the source of getFromUrl(String url)

Description

get From Url

License

Open Source License

Declaration

public static String getFromUrl(String url) throws MalformedURLException, IOException 

Method Source Code

//package com.java2s;
/*//from  w w  w  .j  a  v a  2s.c  o m
 * This file is part of TILT.
 *
 *  TILT is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  TILT is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with TILT.  If not, see <http://www.gnu.org/licenses/>.
 *  (c) copyright Desmond Schmidt 2014
 */

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static String getFromUrl(String url) throws MalformedURLException, IOException {
        URL loc = new URL(url);
        URLConnection pagesService = loc.openConnection();
        InputStream is = pagesService.getInputStream();
        StringBuilder sb = new StringBuilder();
        while (is.available() != 0) {
            byte[] data = new byte[is.available()];
            is.read(data);
            sb.append(new String(data));
        }
        is.close();
        return sb.toString();
    }
}

Related

  1. getContainerUrl(URL url, String resourceInThatDir)
  2. getCookies(URLConnection conn, Map> store)
  3. getDataFromServer(URL url)
  4. getDefaultUrlConnection(URL url)
  5. getFeedReader(URL feedUrl)
  6. getGlobalAddress(String url)
  7. getGlobalIPAddress(URL automationPage)
  8. getHeaderFieldLong(URLConnection conn, String name, long Default)
  9. getHTML(String url, boolean removeNonLatinChars)