Here you can find the source of readListFile(URL listFile)
Parameter | Description |
---|---|
listFile | the url to read from |
public static String[] readListFile(URL listFile) throws IOException
//package com.java2s; /*/* w ww . j a va 2s .c o m*/ * Copyright 2004 Niclas Hedhman * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. * * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.net.URL; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; public class Main { /** * Read a file and return the list of lines in an array of strings. * @param listFile the url to read from * @return the lines * @exception IOException if a read error occurs */ public static String[] readListFile(URL listFile) throws IOException { ArrayList list = new ArrayList(); InputStream stream = openInputStream(listFile); try { InputStreamReader isr = new InputStreamReader(stream, "UTF-8"); BufferedReader reader = new BufferedReader(isr); String line = reader.readLine(); while (line != null) { list.add(line); line = reader.readLine(); } String[] items = new String[list.size()]; list.toArray(items); return items; } finally { stream.close(); } } private static InputStream openInputStream(URL url) throws IOException { try { return url.openStream(); } catch (IOException e) { System.out.println("#URL: " + url); System.out.println(e.toString()); throw e; } } }