Here you can find the source of readFileToLines(String inFile, String inCharset)
public static List<String> readFileToLines(String inFile, String inCharset) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; public class Main { public static List<String> readFileToLines(String inFile, String inCharset) throws IOException { return inFile == null ? new ArrayList<>(0) : readFileToLines(new File(inFile), inCharset); }//w ww . j a v a2 s.c o m public static List<String> readFileToLines(File inFile, String inCharset) throws IOException { return inFile == null ? new ArrayList<>(0) : readFileToLines(inFile, inCharset == null ? null : Charset.forName(inCharset)); } public static List<String> readFileToLines(String inFile, Charset inCharset) throws IOException { return inFile == null ? new ArrayList<>(0) : readFileToLines(new File(inFile), inCharset); } public static List<String> readFileToLines(File inFile, Charset inCharset) throws IOException { if (!isFile(inFile)) { return null; } inCharset = defaultIfNull(inCharset, Charset.defaultCharset()); final List<String> theLines = new ArrayList<>(); try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(inFile), inCharset))) { while (r.ready()) { theLines.add(r.readLine()); } } return theLines; } public static boolean isFile(File inFile) { return inFile != null && inFile.isFile(); } public static boolean isFile(String inFilePath) { return isNotBlank(inFilePath) && isFile(new File(inFilePath)); } public static <T> T defaultIfNull(T inValue, T inDefault) { return inValue == null ? inDefault : inValue; } public static Charset defaultCharset(String inCharset) { try { return Charset.forName(inCharset); } catch (Exception e) { return Charset.defaultCharset(); } } public static boolean isNotBlank(String inValue) { return !isBlank(inValue); } public static boolean isBlank(String inValue) { return inValue == null || inValue.trim().isEmpty(); } }