Java Utililty Methods Text File Read by Encode

List of utility methods to do Text File Read by Encode

Description

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

Method

StringgetFileContent(File file, String charset)
get File Content
StringBuffer sb = new StringBuffer();
try {
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
    String line = br.readLine();
    while (line != null) {
        sb.append(line).append("\n\r");
        line = br.readLine();
    br.close();
    return sb.toString();
} catch (Exception e) {
    return null;
StringgetFileContent(File file, String charsetName)
get File Content
if (file == null)
    return null;
BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));
String content;
StringBuilder sb = new StringBuilder();
while (true) {
    content = bf.readLine();
    if (content == null) {
...
StringgetFileContent(FileInputStream fis, String encoding)
get File Content
BufferedReader br = new BufferedReader(new InputStreamReader(fis, encoding));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
    sb.append(line);
    sb.append('\n');
return sb.toString();
...
StringgetFileContent(InputStream is, String encoding)
get File Content
BufferedReader buff = new BufferedReader(new InputStreamReader(is, encoding));
String content = getContent(buff);
buff.close();
return content;
StringgetFileContentAsString(File file, String encoding)
Copies the contents of the given file to a string.
FileInputStream fis = new FileInputStream(file);
return getStreamAsString(fis, encoding);
StringgetFileContentAsString(File file, String encoding)
Get the content (as string) of the given file.
return new String(getFileContentAsBytes(file), encoding);
StringgetFileContentAsString(File file, String encoding)
get File Content As String
FileInputStream is = new FileInputStream(file);
return new String(getStreamContentAsBytes(is), encoding);
StringgetFileContentAsString(String filePath, String fileEncoding)
get File Content As String
StringBuilder text = new StringBuilder();
String newLine = System.getProperty("line.separator");
try (Scanner scanner = new Scanner(new FileInputStream(filePath), fileEncoding)) {
    boolean isFirstLine = true;
    while (scanner.hasNextLine()) {
        if (isFirstLine) {
            text.append(scanner.nextLine());
            isFirstLine = false;
...
StringgetFileContents(InputStream stream, String encoding)
get File Contents
StringBuilder contents = new StringBuilder();
char[] buffer = new char[2048];
int count;
try {
    try (Reader in = new InputStreamReader(stream, encoding)) {
        while ((count = in.read(buffer)) > 0) {
            contents.append(buffer, 0, count);
} catch (IOException ioe) {
    return null;
return contents.toString();
StringgetFileContents(String filename, String encoding)
get File Contents
return getContents(new FileInputStream(filename), encoding);