| package com.javaweb.third.baidu.util; | 
|   | 
| import java.io.*; | 
|   | 
| /** | 
|  * 文件读取工具类 | 
|  * @author wujiyue | 
|  */ | 
| public class FileUtil { | 
|   | 
|     /** | 
|      * 根据文件路径读取byte[] 数组 | 
|      */ | 
|     public static byte[] readFileByBytes(String filePath) throws IOException { | 
|         File file = new File(filePath); | 
|         if (!file.exists()) { | 
|             throw new FileNotFoundException(filePath); | 
|         } else { | 
|             ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); | 
|             BufferedInputStream in = null; | 
|   | 
|             try { | 
|                 in = new BufferedInputStream(new FileInputStream(file)); | 
|                 short bufSize = 1024; | 
|                 byte[] buffer = new byte[bufSize]; | 
|                 int len1; | 
|                 while (-1 != (len1 = in.read(buffer, 0, bufSize))) { | 
|                     bos.write(buffer, 0, len1); | 
|                 } | 
|   | 
|                 byte[] var7 = bos.toByteArray(); | 
|                 return var7; | 
|             } finally { | 
|                 try { | 
|                     if (in != null) { | 
|                         in.close(); | 
|                     } | 
|                 } catch (IOException var14) { | 
|                     var14.printStackTrace(); | 
|                 } | 
|   | 
|                 bos.close(); | 
|             } | 
|         } | 
|     } | 
| } |