Java InputStreamReader Read readFile(final File inputFile)

Here you can find the source of readFile(final File inputFile)

Description

read File

License

Open Source License

Declaration

static String readFile(final File inputFile) throws IOException 

Method Source Code

//package com.java2s;
/**/*from  www  .j  a  v  a  2  s  .co m*/
 * TaskUtils.java
 *
 * Copyright (C) 2010,  Volker Boerchers
 *
 * Translator.java is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Translator.java 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 General Public License for more details.
 */

import java.io.File;

import java.io.FileInputStream;

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

public class Main {
    static String readFile(final File inputFile) throws IOException {
        InputStreamReader in = null;
        try {
            in = new InputStreamReader(new FileInputStream(inputFile), "US-ASCII");
            StringBuilder builder = new StringBuilder();
            final char[] buf = new char[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                builder.append(buf, 0, len);
            }
            return builder.toString();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    // can't help it
                }
            }
        }
    }
}

Related

  1. readFile(File path)
  2. readFile(File resultFile)
  3. readFile(File target)
  4. readFile(FileInputStream file)
  5. readFile(final File file)
  6. readFile(final String aFileName)
  7. readFile(final String path)
  8. readFile(IFile file)
  9. readFile(IFile theFile)