Here you can find the source of readListFile(URL listFile)
Parameter | Description |
---|---|
listFile | the url to read from |
Parameter | Description |
---|---|
IOException | if a read error occurs |
public static String[] readListFile(URL listFile) throws IOException
//package com.java2s; /*/*from ww w . ja v a 2 s . co 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.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.util.ArrayList; 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 * * @throws IOException if a read error occurs */ public static String[] readListFile(URL listFile) throws IOException { ArrayList<String> list = new ArrayList<String>(); InputStream stream = listFile.openStream(); 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(); } } }