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 byte[] readFile(String fileName) 

Method Source Code


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

import java.io.BufferedInputStream;
import java.io.DataInputStream;

import java.io.FileInputStream;

public class Main {
    public static byte[] readFile(String fileName) {
        try {//ww  w.  ja va2  s. c o  m
            DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName)));
            int n = in.available();
            byte[] t = new byte[n];
            int i = 0;
            while (in.available() != 0) {
                t[i] = in.readByte();
                i++;
            }
            in.close();
            return t;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. readFile(String file)
  2. readFile(String filename)
  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)