Here you can find the source of fileToStringList(String filePath)
Parameter | Description |
---|---|
filePath | - The path of the file to read from |
Parameter | Description |
---|---|
IOException | If there's an error while reading from the file |
public static List<String> fileToStringList(String filePath) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 MCForge - Modified for use with Chatterbox * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html//from w ww . j av a 2 s. co m ******************************************************************************/ import java.io.FileReader; import java.io.IOException; import java.io.LineNumberReader; import java.util.ArrayList; import java.util.List; public class Main { /** * Reads the contents of the specified file * * @param filePath * - The path of the file to read from * * @return A string list with the contents of the read file * @throws IOException * If there's an error while reading from the file */ public static List<String> fileToStringList(String filePath) throws IOException { LineNumberReader reader = new LineNumberReader(new FileReader(filePath)); List<String> lines = new ArrayList<String>(); String line; while ((line = reader.readLine()) != null) lines.add(line); reader.close(); return lines; } }