Java BufferedReader Read readFileWithoutLineBreak(String filename, boolean skipEmptyLine)

Here you can find the source of readFileWithoutLineBreak(String filename, boolean skipEmptyLine)

Description

read File Without Line Break

License

Open Source License

Declaration

public static String readFileWithoutLineBreak(String filename,
            boolean skipEmptyLine) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    public static String readFileWithoutLineBreak(String filename,
            boolean skipEmptyLine) throws IOException {
        StringBuilder sb = new StringBuilder();

        BufferedReader br = new BufferedReader(new FileReader(filename));
        try {//from   ww w. j av  a2  s. c om
            String line;
            while ((line = br.readLine()) != null) {
                if (skipEmptyLine && line.trim().length() == 0) {
                    continue;
                }
                sb.append(line);
            }
        } finally {
            br.close();
        }
        return sb.toString();
    }
}

Related

  1. readFileToHashMap(String filePath, String separator, boolean valueFirst)
  2. readFileToList(String fileName, List list)
  3. readFileToList(String path, String split)
  4. readFileToListOfStrings(File file)
  5. readFileValue(File file)