Java File Read getFileContent(final File f)

Here you can find the source of getFileContent(final File f)

Description

get File Content

License

Open Source License

Declaration

public static byte[] getFileContent(final File f) throws Exception 

Method Source Code

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

import java.io.BufferedInputStream;

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

public class Main {
    public static byte[] getFileContent(final File f) throws Exception {
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final BufferedInputStream in = new BufferedInputStream(
                new FileInputStream(f));
        final byte[] buffer = new byte[40960];
        while (in.available() > 0) {
            final int s = in.read(buffer);
            out.write(buffer, 0, s);/*from  w  w  w . j  a v a2 s .com*/
        }
        // dispose all the resources after using them.
        in.close();
        return out.toByteArray();
    }
}

Related

  1. getFileContent(File file, int bufferSize)
  2. getFileContent(File pFile)
  3. getFileContent(final File file)
  4. getFileContent(final File srcFile)
  5. getFileContent(final String fileName)
  6. getFileContent(final String p_filename)