Java InputStreamReader Read readFileAll(File file, String charsetName)

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

Description

read File All

License

Open Source License

Declaration

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

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static String readFileAll(File file, String charsetName) throws IOException {
        return readInputStreamAll(new FileInputStream(file), charsetName);
    }/*from   ww  w  .  ja v a2 s . com*/

    public static String readFileAll(File file) throws IOException {
        return readFileAll(file, "UTF-8");
    }

    public static String readInputStreamAll(InputStream inputStream, String charsetName) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, charsetName));
        StringBuilder sb = new StringBuilder();
        int c;
        while ((c = reader.read()) != -1) {
            sb.append((char) c);
        }
        reader.close();
        return sb.toString();
    }

    public static String readInputStreamAll(InputStream inputStream) throws IOException {
        return readInputStreamAll(inputStream, "UTF-8");
    }
}

Related

  1. readFile(String path)
  2. readFile(String path)
  3. readFile(String path, String charset)
  4. readFile(ZipInputStream zin)
  5. readFileAddLine(String filePath, Object object)
  6. readFileAsArray(String path)
  7. readFileAsJson(String path)
  8. readFileAsList(String path)
  9. readFileByCharAsString(String path, String encode)