FileInputStream stream = new FileInputStream(f); ByteArrayOutputStream out = new ByteArrayOutputStream(1000); byte[] b = new byte[1000]; int n; while ((n = stream.read(b)) != -1) { out.write(b, 0, n); } stream.close(); out.close(); return out.toByteArray();
File转byte[]
最新推荐文章于 2024-01-15 15:08:13 发布
本文介绍了一种使用Java实现文件读取并将其转换为字节数组的方法。通过FileInputStream从文件中读取数据,利用ByteArrayOutputStream将读取的数据收集到内存中,并最终返回转换后的字节数组。

2794

被折叠的 条评论
为什么被折叠?



