Java File Read by Charset fileToString(final File f, final Charset c)

Here you can find the source of fileToString(final File f, final Charset c)

Description

file To String

License

Open Source License

Declaration

public static String fileToString(final File f, final Charset c) throws IOException 

Method Source Code

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

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.nio.charset.Charset;

public class Main {
    public static String fileToString(final File f, final Charset c) throws IOException {
        return new String(fileToByteArray(f), c);
    }//  ww  w  .ja va 2s  . c  om

    public static byte[] fileToByteArray(final File f) throws IOException {
        final FileInputStream is = new FileInputStream(f);
        final byte[] ret = new byte[(int) f.length()];
        int p = 0;
        while (p < ret.length)
            p += is.read(ret, p, ret.length - p);
        is.close();
        return ret;
    }
}

Related

  1. bomStream(String charset, String file)
  2. copyFileWithEolConversion(File inFile, File outFile, Charset charset)
  3. detectCharset(File f, String[] charsets)
  4. doTranseFileCharset(File srcFile, File destFile, String srcCharsetName, String destCharsetName)
  5. fileContent(File file, Charset charset)
  6. fileToString(final Path path, final Charset charset)
  7. findPattern(File file, Charset charset, String patternString)
  8. fixture(String filename, Charset charset)
  9. getContent(File file, String charsetName)