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(); } }
java reads a local file into a memory BYTE array
Guess you like
Origin blog.csdn.net/yz18931904/article/details/127594221
Recommended
Ranking