Java FileInputStream Read readFile(File src)

Here you can find the source of readFile(File src)

Description

read File

License

Open Source License

Declaration

public static byte[] readFile(File src) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2009 Oracle. 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.
 * /*from  w ww  .  j  a v  a2 s  .co  m*/
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/

import java.io.File;

import java.io.IOException;

public class Main {
    public static byte[] readFile(File src) throws IOException {
        java.io.FileInputStream fin = new java.io.FileInputStream(src);
        try {
            long fileLen = src.length();
            if (fileLen > Integer.MAX_VALUE)
                throw new IOException("file length too big to be read by FileUtil.readFile: " + fileLen);

            byte[] bytes = new byte[(int) fileLen];
            fin.read(bytes);
            return bytes;
        } finally {
            fin.close();
        }
    }
}

Related

  1. readFile(File file, String encoding)
  2. readFile(File fyl)
  3. readFile(File path)
  4. readfile(File path)
  5. readFile(File source)
  6. readFile(File srcFile, OutputStream destStream)
  7. readFile(File target)
  8. readFile(FileInputStream fileinputstream, byte abyte0[])
  9. readFile(final File file)