Java Utililty Methods Text File Read Line

List of utility methods to do Text File Read Line

Description

The list of methods to do Text File Read Line are organized into topic(s).

Method

ListreadLines(File file)
read Lines
BufferedReader br = null;
try {
    List<String> lines = newArrayList();
    if (!file.exists()) {
        throw new FileNotFoundException();
    br = new BufferedReader(new FileReader(file));
    String line = br.readLine();
...
ListreadLines(File file, boolean ignoreComments)
read Lines
if (!file.exists() || !file.isFile()) {
    return new ArrayList<>();
List<String> lines = new ArrayList<>();
BufferedReader reader = null;
try {
    reader = new BufferedReader(new FileReader(file));
    String line;
...
String[]readLines(File file, int maxArraySize)
read Lines
try (FileInputStream in = new FileInputStream(file)) {
    return readLines(in, maxArraySize);
ListreadLines(File file, String charset)
Reads lines from a file.
FileInputStream fis = new FileInputStream(file);
try {
    return readLines(fis, charset);
} finally {
    if (fis != null) {
        fis.close();
ListreadLines(File file, String charsetName)
read Lines
List<String> lines = new ArrayList<String>();
if (file.exists()) {
    InputStream in = null;
    Reader reader = null;
    BufferedReader bufferedReader = null;
    try {
        in = new FileInputStream(file);
        reader = charsetName == null ? new InputStreamReader(in) : new InputStreamReader(in, charsetName);
...
ListreadLines(File file, String encoding)
Get the contents of an InputStream as a list of Strings, one entry per line, using the specified character encoding.
InputStreamReader reader = null;
try {
    reader = new InputStreamReader(openInputStream(file), encoding);
    return readLines(reader);
} finally {
    reader.close();
ListreadLines(File file, String encoding)

Reads the contents of a file line by line to a List of Strings.

InputStream in = new FileInputStream(file);
try {
    return readLines(in, encoding);
} finally {
    closeQuietly(in);
StringBuilderreadLines(File file, String outputLineEnding)
read Lines
StringBuilder data = new StringBuilder();
BufferedReader in = null;
try {
    in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
    String str = "";
    while ((str = in.readLine()) != null) {
        data.append(str + outputLineEnding);
} finally {
    if (in != null) {
        in.close();
return data;
ListreadLines(File inputFile)
Reads the contents of the given ascii file.
List<String> lines = new ArrayList<>();
try {
    BufferedReader input = new BufferedReader(new FileReader(inputFile));
    try {
        String line = input.readLine();
        while (line != null) {
            lines.add(line);
            line = input.readLine();
...
ListreadLines(File inputFile, String encoding)
Read a file into a list of lines
try {
    List<String> result = new ArrayList<>();
    BufferedReader in = openForReading(inputFile, encoding);
    try {
        String line;
        while ((line = in.readLine()) != null) {
            result.add(line.trim());
    } finally {
        in.close();
    return result;
} catch (Exception e) {
    throw new RuntimeException(e);