Java File Read via ByteBuffer readFC(String fname, int length)

Here you can find the source of readFC(String fname, int length)

Description

read FC

License

Apache License

Declaration

public static float[] readFC(String fname, int length) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.channels.FileChannel;

public class Main {
    public static float[] readFC(String fname, int length) throws IOException {
        float[] res = new float[length];
        FileChannel inChannel = new RandomAccessFile(fname, "rw").getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(4 * res.length);
        inChannel.read(buffer);/*from   w  ww  . j  a  v a  2  s . co  m*/
        buffer.flip();
        FloatBuffer buffer2 = buffer.asFloatBuffer();
        for (int i = 0; i < res.length; i++) {
            res[i] = buffer2.get(i);
        }
        inChannel.close();
        return res;
    }
}

Related

  1. readDouble(byte[] src, int pointer)
  2. readDouble(FileChannel fileChannel, ByteOrder byteOrder)
  3. readDouble(final byte[] bytes, final int length, final int offset)
  4. readEntireFile(java.io.File file)
  5. readerToString(Reader reader)
  6. readFile(File file)
  7. readFile(File file)
  8. readFile(File file)
  9. readFile(File file)