Java URL Read readListFromURL(URL p_url)

Here you can find the source of readListFromURL(URL p_url)

Description

Reads a list of lines from a url

License

Open Source License

Parameter

Parameter Description
p_url The input url

Return

The list of string lines

Declaration

public static List<String> readListFromURL(URL p_url) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

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

import java.net.URL;
import java.net.URLConnection;

import java.util.LinkedList;
import java.util.List;

public class Main {
    /**/*from   ww w. j  av  a2 s. co  m*/
     * Reads a list of lines from a url
     * @param p_url The input url
     * @return The list of string lines
     */
    public static List<String> readListFromURL(URL p_url) {
        List<String> text = new LinkedList<String>();
        try {
            URLConnection urlc = p_url.openConnection();
            InputStreamReader fisr = new InputStreamReader(urlc.getInputStream());
            BufferedReader br = new BufferedReader(fisr);

            String inLine = br.readLine();
            while (inLine != null) {
                text.add(inLine);
                inLine = br.readLine();
            }
        } catch (IOException e) {
            return null;
        }
        return text;
    }
}

Related

  1. getUrlInfos(String urlAsString, int timeout)
  2. getUrlSource(String url)
  3. getUrlStatus(String url)
  4. getUrlTxt(String url)
  5. readAsString(final URL url)
  6. readPage(String url)
  7. readStringFromURL(String sourceURL)
  8. readUrl(final String strUrl)
  9. readUrl(final String url)