Here you can find the source of readToBuffer(final String filename)
Parameter | Description |
---|---|
filename | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static ByteBuffer readToBuffer(final String filename) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; public class Main { /**/*www . j a va 2 s. c o m*/ * Get byte buffer from file path. * * @param filename * @return * @throws IOException */ public static ByteBuffer readToBuffer(final String filename) throws IOException { final File file = new File(filename); final ByteBuffer bytebBuffer = ByteBuffer.allocate((int) file.length()); final FileInputStream fis = new FileInputStream(filename); bytebBuffer.rewind(); int b = 0; final byte[] buf = new byte[1024]; while ((b = fis.read()) != -1) { bytebBuffer.put((byte) b); } return bytebBuffer; } }