Java File Read by Charset fileContent(File file, Charset charset)

Here you can find the source of fileContent(File file, Charset charset)

Description

file Content

License

Open Source License

Declaration

public static String fileContent(File file, Charset charset) 

Method Source Code


//package com.java2s;
/*//from ww w  .  j a v a  2  s  .co m
 * SonarQube CSS Plugin
 * Copyright (C) 2013-2016 Tamas Kende and David RACODON
 * mailto: kende.tamas@gmail.com and david.racodon@gmail.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

public class Main {
    public static String fileContent(File file, Charset charset) {
        String fileContent;
        try {
            fileContent = Files.toString(file, charset);
        } catch (IOException e) {
            throw new IllegalStateException("Could not read " + file, e);
        }
        return fileContent;
    }
}

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. fileToString(final File f, final Charset c)
  6. fileToString(final Path path, final Charset charset)
  7. findPattern(File file, Charset charset, String patternString)
  8. fixture(String filename, Charset charset)