Java FileInputStream Read readFile(String filename)

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

Description

read File

License

Open Source License

Declaration

public static List<Byte> readFile(String filename) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Byte> readFile(String filename) {
        List<Byte> result = new ArrayList<>();

        try (FileInputStream file = new FileInputStream(filename)) {
            byte[] buffer = new byte[64 * 1024];
            int bytesRead = 0;

            while ((bytesRead = file.read(buffer)) > 0) {
                for (int i = 0; i < bytesRead; i++)
                    result.add(buffer[i]);
            }/* w  ww  . java 2s.com*/
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return result;
    }
}

Related

  1. readFile(String file)
  2. readFile(String file)
  3. readFile(String filename)
  4. readFile(String fileName)
  5. readFile(String fileName)
  6. readFile(String fileName)
  7. readFile(String filename)
  8. readFile(String fileName)
  9. readFile(String fileName)