Java File Content Read getFileContents(File testFile)

Here you can find the source of getFileContents(File testFile)

Description

get File Contents

License

Open Source License

Declaration

public static String getFileContents(File testFile) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011, 2015 EclipseSource and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w  w w. ja  va2 s.  c o m
 *    EclipseSource - initial API and implementation
 ******************************************************************************/

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Main {
    public static String getFileContents(File testFile) {
        // TODO [rst] Buffer can get very big with the wrong file
        byte[] buffer = new byte[(int) testFile.length()];
        try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(testFile))) {
            bis.read(buffer);
            return new String(buffer);
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }
}

Related

  1. getFileContents(File f)
  2. getFileContents(File f)
  3. getFileContents(File file)
  4. getFileContents(File file)
  5. getFileContents(File methodPatch)
  6. getFileContents(final File f)
  7. getFileContents(final File file)
  8. getFileContents(String filename)
  9. getFileContents(String fileName)