Read a file using java

This is a simple code to read a file from your disk. I used here common-io for IOUtils class. If you call readfile with a file path name as String this code read the corresponding data from the file and give a byte array as a response for the data of this file.
  public static byte[] readFile(String path) throws Exception
    {
        InputStream input = new FileInputStream(new File(path));
        byte[] data= IOUtils.toByteArray(input);
        return data;

    }

Reactions

Post a Comment

0 Comments