Java URL Load readContentsToList(URL url)

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

Description

Reads the contents of the website at the specified URL

License

Open Source License

Parameter

Parameter Description
url - The URL of the website to read from

Exception

Parameter Description
IOException If there's an error while reading from the website

Return

A string list with the contents of the read website

Declaration

public static List<String> readContentsToList(URL url) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 MCForge./*  w  w w.j  a  v  a 2  s .c om*/
 * 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
 ******************************************************************************/

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**
     * Reads the contents of the website at the specified URL
     * 
     * @param url - The URL of the website to read from
     * 
     * @return A string list with the contents of the read website
     * @throws IOException If there's an error while reading from the website
     */
    public static List<String> readContentsToList(URL url) throws IOException {
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(url.openStream()));
        List<String> lines = new ArrayList<String>();
        String line;
        while ((line = reader.readLine()) != null)
            lines.add(line);
        reader.close();
        return lines;
    }
}

Related

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