Java FileInputStream Read readFileBytes(String filename)

Here you can find the source of readFileBytes(String filename)

Description

read File Bytes

License

Open Source License

Declaration

static byte[] readFileBytes(String filename) throws IOException 

Method Source Code

//package com.java2s;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    static byte[] readFileBytes(String filename) throws IOException {
        File file = new File(filename);
        InputStream is = new FileInputStream(file);
        byte[] result = new byte[(int) file.length()];
        int count = 0;
        while (count < result.length) {
            int r = is.read(result, count, result.length - count);
            if (r < 0) {
                break;
            }//  w ww.  j  a v a 2  s .co  m
            count += r;
        }
        is.close();
        return result;
    }
}

Related

  1. readFileBinaries(File file)
  2. readFileBinary(String filename)
  3. readFileBytes(File file)
  4. readFileBytes(File file)
  5. readFileBytes(String file)
  6. readFileBytes(String fileName)
  7. readFileBytes(String filePath)
  8. readFileEndAsString(File file, int size_limit)
  9. readFileEx(String... file)