Java FileInputStream Read readFile(String destination)

Here you can find the source of readFile(String destination)

Description

readFile

License

Open Source License

Parameter

Parameter Description
destination a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static byte[] readFile(String destination) throws IOException 

Method Source Code


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

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

import java.io.IOException;

public class Main {
    /**// w w w.j  av a  2 s  . com
     * readFile
     * 
     * @param destination
     * @return
     * @throws IOException
     */
    public static byte[] readFile(String destination) throws IOException {

        File temp = new File(destination);

        if (temp.exists()) {
            FileInputStream fis = new FileInputStream(temp);
            byte[] data = new byte[(int) temp.length()];
            try {
                fis.read(data);
            } finally {
                fis.close();
            }
            return data;
        }

        return new byte[0];
    }

    /**
     * existFile
     * 
     * @param path
     * @return
     */
    public static boolean exists(String path) {

        try {
            File temp = new File(path);
            return temp.exists();
        } catch (Exception e) {
            // ignore
        }
        return false;
    }
}

Related

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