Here you can find the source of readFile(String filename, boolean skipEmptyLine)
Parameter | Description |
---|---|
filename | String |
skipEmptyLine | boolean |
Parameter | Description |
---|---|
IOException | an exception |
public static String[] readFile(String filename, boolean skipEmptyLine) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Main { /**//from w ww. j av a2 s .c om * Read file to array of String. * * @param filename * String * @param skipEmptyLine * boolean * @throws IOException * @return String[] */ public static String[] readFile(String filename, boolean skipEmptyLine) throws IOException { final List<String> result = new ArrayList<String>(); BufferedReader br = new BufferedReader(new FileReader(filename)); try { String line; while ((line = br.readLine()) != null) { if (skipEmptyLine && line.trim().length() == 0) { continue; } result.add(line); } } finally { br.close(); } return (String[]) result.toArray(new String[0]); } /** * Read file to array of String. * * @param filename * String * @throws IOException * @return String[] */ public static String[] readFile(String filename) throws IOException { return readFile(filename, false); } }