Java FileInputStream Read readFile(InputStream ios)

Here you can find the source of readFile(InputStream ios)

Description

read File

License

Open Source License

Declaration

public static byte[] readFile(InputStream ios) throws IOException 

Method Source Code


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

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

public class Main {

    public static byte[] readFile(File file) throws IOException {
        FileInputStream fis = new FileInputStream(file);
        byte[] bs = readFile(fis);
        return bs;
    }/*w w w .  j  av a  2s . c om*/

    public static byte[] readFile(InputStream ios) throws IOException {
        ByteArrayOutputStream ous = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int read = 0;
        while ((read = ios.read(buffer)) != -1) {
            ous.write(buffer, 0, read);
        }
        byte[] bs = ous.toByteArray();
        ous.close();
        ios.close();
        return bs;
    }
}

Related

  1. readFile(final File file)
  2. readFile(final File file)
  3. readFile(final File file)
  4. readFile(final InputStream stream)
  5. readFile(final String fileNamePath)
  6. readFile(InputStream iStream)
  7. readFile(String destination)
  8. readFile(String file)
  9. readFile(String file)