Java FileInputStream Read readFile(File file)

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

Description

read File

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2009 Tasktop Technologies 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  ww .j  a  v a 2s. c  om*/
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

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

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static byte[] readFile(File file) throws IOException {
        if (file.length() > 10000000) {
            throw new IOException("File too big: " + file.getAbsolutePath()
                    + ", size: " + file.length());
        }

        byte[] data = new byte[(int) file.length()];
        InputStream in = new FileInputStream(file);
        try {
            in.read(data);
        } finally {
            in.close();
        }
        return data;
    }
}

Related

  1. readFile(File file)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(File file)
  5. readFile(File file)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)