Java InputStream Read Bytes readBytes(InputStream is)

Here you can find the source of readBytes(InputStream is)

Description

read Bytes

License

Apache License

Declaration

public static byte[] readBytes(InputStream is) 

Method Source Code


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

import java.io.*;

public class Main {

    public static byte[] readBytes(String fileName) {
        return readByte(new File(fileName));
    }/*from ww  w.  jav  a 2s  .  com*/

    public static byte[] readBytes(InputStream is) {
        try {
            int size = is.available();
            byte[] buf = new byte[size];
            is.read(buf);
            return buf;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static byte[] readByte(File f) {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(f);
            return readBytes(fis);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
}

Related

  1. readBytes(InputStream inputStream, int length)
  2. readBytes(InputStream inputStream, int numberOfBytes)
  3. readBytes(InputStream inputStream, int numberOfBytes)
  4. readBytes(InputStream ins, byte[] buf, int size)
  5. readBytes(InputStream is)
  6. readBytes(InputStream is)
  7. readBytes(InputStream is)
  8. readBytes(InputStream is)