Java URL Load readContents(URL url)

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

Description

read Contents

License

Open Source License

Declaration

public static String readContents(URL url) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2012 Nikita Zhiltsov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html//ww w . java 2s  .  co m
 * 
 * Contributors:
 *     Nikita Zhiltsov - initial API and implementation
 *     Azat Khasanshin - implementation
 ******************************************************************************/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.net.URL;

public class Main {
    public static String readContents(URL url) throws IOException {
        InputStream inputStream = url.openStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        StringBuffer contentsBuffer = new StringBuffer();
        try {
            String value;
            while ((value = reader.readLine()) != null) {
                contentsBuffer.append(value);
                contentsBuffer.append("\n");
            }
        } finally {
            reader.close();
            inputStream.close();
        }
        return contentsBuffer.toString();
    }
}

Related

  1. readBytes(URL url)
  2. readBytesFromURL(String url)
  3. readBytesFromUrl(URL url)
  4. readContent(URL url)
  5. readContentFromFile(URL u, String encoding)
  6. readContentsToArray(URL url)
  7. readContentsToList(URL url)
  8. readContentsToString(URL url)
  9. readData(String url)