Java Byte Array from getBytes(String filePath, long startPos, long endPos)

Here you can find the source of getBytes(String filePath, long startPos, long endPos)

Description

get Bytes

License

Open Source License

Declaration

public static byte[] getBytes(String filePath, long startPos, long endPos) 

Method Source Code


//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    private static final int DEFAULT_BUFF_SIZE = 1024;
    private static final int UNIT_LEN = 8;

    public static byte[] getBytes(String filePath, long startPos, long endPos) {
        byte[] buffer = null;
        try {/*from  ww  w.  j  av  a 2 s  .c o m*/
            File file = new File(filePath);
            FileInputStream fis = new FileInputStream(file);
            ByteArrayOutputStream bos = new ByteArrayOutputStream(DEFAULT_BUFF_SIZE * UNIT_LEN);
            byte[] b = new byte[DEFAULT_BUFF_SIZE * UNIT_LEN];
            int n;
            while ((n = fis.read(b)) != -1) {
                bos.write(b, 0, n);
            }
            fis.close();
            bos.close();
            buffer = bos.toByteArray();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer;
    }
}

Related

  1. getBytes(String data, String encoding)
  2. getBytes(String defaultPlain)
  3. getBytes(String fileName)
  4. getBytes(String fileName)
  5. getBytes(String filePath)
  6. getBytes(String fileUrl)
  7. getBytes(String input)
  8. getBytes(ZipFile archive, ZipEntry entry)
  9. getBytes(ZipInputStream zipInputStream)