Here you can find the source of readFile(String filePath)
Parameter | Description |
---|---|
filePath | specified file path |
byte[]
file content
public static byte[] readFile(String filePath)
//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; } }