Java FileInputStream Read readFile(String filePath)

Here you can find the source of readFile(String filePath)

Description

read file to byte[] with specified file path

License

Open Source License

Parameter

Parameter Description
filePath specified file path

Return

byte[] file content

Declaration

public static byte[] readFile(String filePath) 

Method Source Code

//package com.java2s;
/*/*from  w  w w .j  av a2s. c  om*/
 * File: $RCSfile$
 *
 * Copyright (c) 2005 Wincor Nixdorf International GmbH,
 * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information
 * of Wincor Nixdorf ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered
 * into with Wincor Nixdorf.
 */

import java.io.File;

import java.io.IOException;
import java.io.FileInputStream;

public class Main {
    /**
     * read file to byte[] with specified file path
     *
     * @param filePath specified file path
     * @return <code>byte[]</code> file content
     */
    public static byte[] readFile(String filePath) {
        File infoFile = new File(filePath);
        byte[] result = null;
        if (infoFile.exists()) {
            result = new byte[(int) infoFile.length()];
            try {
                FileInputStream fis = new FileInputStream(infoFile);
                fis.read(result);
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
}

Related

  1. readFile(String fileName, String charset)
  2. readFile(String filePath)
  3. readFile(String filePath)
  4. readFile(String filePath)
  5. readFile(String filePath)
  6. readFile(String filePath)
  7. readFile(String filePath)
  8. readFile(String filePathName)
  9. readFile(String fname)