Java Utililty Methods Text File Load

List of utility methods to do Text File Load

Description

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

Method

StringloadTextFile(File textFile)
load Text File
try {
    try (FileInputStream fileStream = new FileInputStream(textFile)) {
        return new String(loadBytes(fileStream));
} catch (IOException e) {
    throw new RuntimeException(e);
StringloadTextFile(final String filePath)
load Text File
final FileReader fileReader = new FileReader(filePath);
final BufferedReader bufReader = new BufferedReader(fileReader);
String line = null;
final StringBuilder result = new StringBuilder();
while ((line = bufReader.readLine()) != null) {
    result.append(line);
bufReader.close();
...
StringloadTextFile(String fileFullPath)
load Text File
StringBuffer text = new StringBuffer();
BufferedReader input;
try {
    File f = new File(fileFullPath);
    input = new BufferedReader(new FileReader(f));
    while (input.readLine() != null) {
        text.append(input.readLine() + "\n");
    input.close();
} catch (Exception ioe) {
    return ioe.getMessage();
return text.toString();
StringloadTextFile(String fileName)
load Text File
BufferedReader br = new BufferedReader(new FileReader(fileName));
String text = "";
try {
    StringBuilder sb = new StringBuilder();
    String line = br.readLine();
    while (line != null) {
        sb.append(line);
        sb.append("\n");
...
ListloadTextFile(String filename)
load Text File
List<String> ls = new ArrayList<String>();
String line = "";
BufferedReader reader = null;
try {
    reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
    while ((line = reader.readLine()) != null) {
        ls.add(line.trim());
} catch (FileNotFoundException fnfe) {
    System.err.println("Erreur fichier : " + filename + " indisponible");
    System.exit(1);
    return null;
} catch (IOException ioe) {
    System.err.println("Erreur sur fichier : " + filename);
    ioe.printStackTrace();
    System.exit(1);
    return null;
} finally {
    if (reader != null)
        reader.close();
return ls;
StringloadTextFile(String fileName)
load Text File
return loadTextFile(fileName, null);
String[]loadTextFile(String filename, int maxLines)
load Text File
String[] tmpLines = new String[maxLines];
BufferedReader file = new BufferedReader(new FileReader(filename));
int n;
try {
    String line = file.readLine();
    for (n = 0; line != null && n < tmpLines.length; n++) {
        tmpLines[n] = line;
        line = file.readLine();
...
ListloadTextFileAsLines(String fileName)
load Text File As Lines
if (!new File(fileName).exists())
    return null;
FileInputStream fileInputStream = new FileInputStream(fileName);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, charsetForTextFiles);
List<String> lines = new ArrayList<String>();
try {
    BufferedReader reader = new BufferedReader(inputStreamReader);
    String line;
...