Java URL Connection url2list(String sURL, String encoding)

Here you can find the source of url2list(String sURL, String encoding)

Description

urllist

License

Open Source License

Declaration

public static List<String> url2list(String sURL, String encoding) 

Method Source Code

//package com.java2s;
/*/* www .  j  a  va2s. c o m*/
 * (C) 2007-2012 Alibaba Group Holding Limited.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 * Authors:
 *   leiwen <chrisredfield1985@126.com> , boyan <killme2008@gmail.com>
 */

import java.io.BufferedReader;

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

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    private static final String UTF_8 = "utf-8";

    public static List<String> url2list(String sURL, String encoding) {
        try {
            URL url = new URL(sURL);
            URLConnection conn = url.openConnection();

            InputStream is = conn.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    is, encoding));
            List<String> list = new ArrayList<String>();
            String line;
            while ((line = br.readLine()) != null) {
                list.add(line);
            }
            return list;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static List<String> url2list(String sURL) {
        return url2list(sURL, UTF_8);
    }
}

Related

  1. shortenUrl(String url)
  2. skip(URLConnection connection, long count)
  3. slurpStream(URLConnection conn)
  4. slurpURL(URL u, String encoding)
  5. slurpURLNoExceptions(URL u)
  6. urlContents(String urlString)
  7. urlExists(String urlString)
  8. URLExists(URL url, StringBuffer errorMsg)
  9. urlifyMap(Long nid, double latitude, double longitude)