将文件转成byte[]文件属组
2016-02-17 16:40
225 查看
/** * * @Description : 读取文件数组 * @Method_Name : fileBuff * @param filePath * @return * @throws IOException * @return : byte[] * @Creation Date : 2015年1月27日 下午5:26:49 * @Author : */ public static byte[] fileBuff(String filePath) throws IOException { File file = new File(filePath); long fileSize = file.length(); if (fileSize > Integer.MAX_VALUE) { //System.out.println("file too big..."); return null; } FileInputStream fi = new FileInputStream(file); byte[] file_buff = new byte[(int) fileSize]; int offset = 0; int numRead = 0; while (offset < file_buff.length && (numRead = fi.read(file_buff, offset, file_buff.length - offset)) >= 0) { offset += numRead; } // 确保所有数据均被读取 if (offset != file_buff.length) { throw new IOException("Could not completely read file " + file.getName()); } fi.close(); return file_buff; }
相关文章推荐
- 《转》IOS 扩展 (Extension)
- python编程常用模板总结
- 网页版Rstudio︱RStudio Server多人在线协作开发
- DEV gridcontrol表格内嵌表格实现思路
- 又到一年加薪时:调薪还是调心?
- python基础学习二 list和tuple(列表和元组)
- 【Boost】Interprocess - 共享内存、文件映射介绍
- WebService上传和下载文件
- css代码纠错机制,与排版
- hibernate关于session的关闭问题
- virtualenv详解
- 我喜欢的工作状态
- 家用游戏机简史
- Java经典问题算法大全
- 最详细的Log4j使用教程
- struct2 学习总结
- 03 不高兴的津津(1.9)
- C 语言关键字
- sql server 2008 非域环境下数据库镜像配置
- css绘制带箭头对话框