public static ByteBuffer readFileToByteBuffer(String filepath1)
{
try
{
File file1 = new File(filepath1);
InputStream is= new FileInputStream(file1);
ByteArrayOutputStream out= new ByteArrayOutputStream();
int count = 0;
byte[] b = new byte[ 8 * 1024];
while( (count=is.read(b)) != -1 )
out.write(b,0,count);
is.close();
return ByteBuffer.wrap(out.toByteArray());
}
catch(Exception e)
{
return null;
}
}
将图片文件转换为ByteBuffer
最新推荐文章于 2024-09-11 20:44:44 发布
本文介绍了一种使用Java语言从文件中读取数据并将其转换为ByteBuffer的方法。此方法通过FileInputStream打开文件,然后利用ByteArrayOutputStream将文件内容逐块读取到内存中,最终将字节数组包装成ByteBuffer返回。
4436

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



