Java URL Load readContentsToArray(URL url)

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

Description

read Contents To Array

License

Open Source License

Declaration

public static String[] readContentsToArray(URL url) throws IOException 

Method Source Code


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

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 {
    public static String[] readContentsToArray(URL url) throws IOException {
        List<String> lines = readContentsToList(url);
        return lines.toArray(new String[lines.size()]);
    }/*  w  w w  .  ja  v  a 2  s.co m*/

    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(String url)
  2. readBytesFromUrl(URL url)
  3. readContent(URL url)
  4. readContentFromFile(URL u, String encoding)
  5. readContents(URL url)
  6. readContentsToList(URL url)
  7. readContentsToString(URL url)
  8. readData(String url)
  9. readFile(URL file)