Java InputStreamReader Read readFileByCharAsString(String path, String encode)

Here you can find the source of readFileByCharAsString(String path, String encode)

Description

read File By Char As String

License

Apache License

Declaration

public static String readFileByCharAsString(String path, String encode) throws IOException 

Method Source Code


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

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static String readFileByCharAsString(String path, String encode) throws IOException {

        InputStream in = new FileInputStream(path);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in, encode));
        StringBuffer contentbuffer = new StringBuffer();
        char[] temp = new char[1024];
        int size = 0;
        while ((size = reader.read(temp, 0, 1024)) != -1) {
            String tempstr = new String(temp, 0, size);
            contentbuffer.append(tempstr);
        }/* w  ww .  j a  va 2s  .com*/

        String content = contentbuffer.toString();
        reader.close();
        return content;
    }
}

Related

  1. readFileAddLine(String filePath, Object object)
  2. readFileAll(File file, String charsetName)
  3. readFileAsArray(String path)
  4. readFileAsJson(String path)
  5. readFileAsList(String path)
  6. readFileCharacters(File file, boolean fix)
  7. readFileData(File file)
  8. readFileData(String directoryLocation, String fileName)
  9. readFileFromClassPath(String file)