Here you can find the source of readLines(String file)
Parameter | Description |
---|---|
file | The file to read lines from |
Parameter | Description |
---|---|
IOException | If there is any error while trying to read from thefile provided |
private static String[] readLines(String file) throws IOException
//package com.java2s; /**//from w w w. j a v a2 s . c o m * This file is part of SecureNIO. Copyright (C) 2014 K. Dermitzakis * <dermitza@gmail.com> * * SecureNIO is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * SecureNIO is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with SecureNIO. If not, see <http://www.gnu.org/licenses/>. */ import java.io.FileReader; import java.io.IOException; import java.io.LineNumberReader; import java.util.ArrayList; public class Main { private static LineNumberReader lr; private static FileReader fr; private static ArrayList<String> lines; /** * Generic read line method implementation from a file. This implementation * allows empty lines and comment lines beginning with #. The method is used * by both {@link #readProtocols(java.lang.String)} and * {@link #readCipherSuites(java.lang.String)} and as such, these methods do * not distinguish between protocols and cipher suites. * * * @param file The file to read lines from * @return A string array containing the valid lines read or null if there * was an error reading the lines * @throws IOException If there is any error while trying to read from the * file provided */ private static String[] readLines(String file) throws IOException { String line; fr = new FileReader(file); lines = new ArrayList<>(); lr = new LineNumberReader(fr); while ((line = lr.readLine()) != null) { if (!line.startsWith("#") && !line.isEmpty()) { lines.add(line); } } fr.close(); lr.close(); String[] ret = lines.toArray(new String[0]); lines.clear(); lines = null; fr = null; lr = null; return ret; } }