Java Text File Read by Encode getFileContent(File file, String charsetName)

Here you can find the source of getFileContent(File file, String charsetName)

Description

get File Content

License

Apache License

Declaration

public static String getFileContent(File file, String charsetName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {

    public static String getFileContent(File file, String charsetName) throws IOException {
        if (file == null)
            return null;
        BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));

        String content;/*from  w  w w .ja va2  s .com*/
        StringBuilder sb = new StringBuilder();
        while (true) {
            content = bf.readLine();
            if (content == null) {
                break;
            }
            sb.append(content.trim());
        }
        bf.close();
        return sb.toString();
    }
}

Related

  1. getFileContent(File file, String charset)
  2. getFileContent(FileInputStream fis, String encoding)
  3. getFileContent(InputStream is, String encoding)
  4. getFileContentAsString(File file, String encoding)
  5. getFileContentAsString(File file, String encoding)