Java Byte Array from getBytes(String fileUrl)

Here you can find the source of getBytes(String fileUrl)

Description

get Bytes

License

Open Source License

Declaration

public static byte[] getBytes(String fileUrl) 

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 {

    public static byte[] getBytes(String fileUrl) {

        File file = new File(fileUrl);
        if (!file.exists()) {
            return null;
        }//  ww w  . j  a va2  s  . c  om

        FileInputStream io = null;
        byte[] data = null;
        try {
            io = new FileInputStream(file);
            data = new byte[io.available()];
            io.read(data);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != io) {
                try {
                    io.close();
                } catch (IOException e2) {
                    e2.printStackTrace();
                }

            }
        }
        return data;
    }

    /**
     * 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. getBytes(String defaultPlain)
  2. getBytes(String fileName)
  3. getBytes(String fileName)
  4. getBytes(String filePath)
  5. getBytes(String filePath, long startPos, long endPos)
  6. getBytes(String input)
  7. getBytes(ZipFile archive, ZipEntry entry)
  8. getBytes(ZipInputStream zipInputStream)
  9. getBytes2(InputStream aStream)