Java FileInputStream Read readFileEx(String... file)

Here you can find the source of readFileEx(String... file)

Description

read File Ex

License

Open Source License

Declaration

public static byte[] readFileEx(String... file) throws IOException 

Method Source Code

//package com.java2s;
/*/*from  w  w  w.j a va  2 s.c  o m*/
 *  Copyright (C) 2010-2016 JPEXS, All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 */

import java.io.ByteArrayOutputStream;

import java.io.FileInputStream;

import java.io.IOException;

public class Main {
    public static byte[] readFileEx(String... file) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        for (String f : file) {
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(f);

                byte[] buf = new byte[4096];
                int cnt;
                while ((cnt = fis.read(buf)) > 0) {
                    baos.write(buf, 0, cnt);
                }
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException ex) {
                        //ignore
                    }
                }
            }
        }
        return baos.toByteArray();
    }
}

Related

  1. readFileBytes(String file)
  2. readFileBytes(String filename)
  3. readFileBytes(String fileName)
  4. readFileBytes(String filePath)
  5. readFileEndAsString(File file, int size_limit)
  6. readFileFully(File file)
  7. readFileInByteArray(String aFileName)
  8. readFileRaw(File file)
  9. readFileToBinary(File lessCSS)