java 將一個本地的文件讀取到内存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));
int bufSize = 1024;
byte[] buffer = new byte[bufSize];
boolean var6 = false;
int len;
while(-1 != (len = in.read(buffer, 0, bufSize))) {
bos.write(buffer, 0, len);
}
byte[] var7 = bos.toByteArray();
return var7;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException var14) {
var14.printStackTrace();
}
bos.close();
}
}
下一篇:
IT行业接项目的方法总结(接私活可用)
