Java URL Load readUrlContent(String address)

Here you can find the source of readUrlContent(String address)

Description

read Url Content

License

Open Source License

Declaration

public static String readUrlContent(String address) throws IOException 

Method Source Code


//package com.java2s;
/*/*from www  .  ja va  2s .  com*/
 * This file is part of MyPet
 *
 * Copyright (C) 2011-2016 Keyle
 * MyPet is licensed under the GNU Lesser General Public License.
 *
 * MyPet 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 3 of the License, or
 * (at your option) any later version.
 *
 * MyPet 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 this program. If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

import java.net.URL;

public class Main {
    public static String readUrlContent(String address) throws IOException {
        StringBuilder contents = new StringBuilder(2048);
        BufferedReader br = null;

        try {
            URL url = new URL(address);
            br = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = br.readLine()) != null) {
                contents.append(line);
            }
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return contents.toString();
    }
}

Related

  1. readURL(URL url)
  2. readUrl(URL url)
  3. readURL(URL url)
  4. readURL(URL url)
  5. readURLasString(URL url)
  6. readURLContents(String UrlText)
  7. readURLJSONArray(String urlString)
  8. readUrlProperties(URL url)
  9. readUrlStream(String urlString)