把文件转化为byte[],java
来源:互联网 发布:php防止接口频繁调用 编辑:程序博客网 时间:2024/04/25 14:29
/** * 把一个文件转化为字节 * * @param file * @return byte[] * @throws Exception */ public static byte[] getByte(File file) throws Exception { byte[] bytes = null; if (file != null) { InputStream is = new FileInputStream(file); int length = (int) file.length(); if (length > Integer.MAX_VALUE) //当文件的长度超过了int的最大值 { System.out.println("this file is max "); return null; } bytes = new byte[length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } //如果得到的字节长度和file实际的长度不一致就可能出错了 if (offset < bytes.length) { System.out.println("file length is error"); return null; } is.close(); } return bytes; }
阅读全文
0 0
- 把文件转化为byte[],java
- java把一个文件转化为byte字节
- Java把一个文件转化为byte字节
- java 把 byte[] 数组转化为String
- 把byte转化为十六进制
- java中把对象转化为byte数组的方法
- java 把byte转化为KB、MB、GB的方法
- 把JAVA程序转化为EXE安装程序文件
- java中InputStream转化为byte[]数组
- Java 中String转化为byte数组
- java中InputStream转化为byte[]数组
- java中类型int转化为Byte
- java中InputStream转化为byte[]数组
- java中InputStream转化为byte[]数组
- java中将byte转化为字母
- java中InputStream转化为byte[]数组
- 如何把rms的记录转化为byte[],
- Java读取文件byte转化String问题
- 4
- [Matlab] MxArray 与 MwArray 使用区别
- nodejs
- oracle对汉字的排序
- 如何找到想要的资源?
- 把文件转化为byte[],java
- 小机上运行ORACLE需要注意的进程调度BUG
- SSH 登录时出现如下错误:Host key verification failed的解决方案
- MySQL5.6密码过期设置
- MyEclipse+Tomcat配置详解
- 【CF360D】Levko and Sets 题解
- 【Github Issues】Glide Issues
- JavaNIO
- C#多线程面面观