Java Path File Read nio readFully(Path filePath)

Here you can find the source of readFully(Path filePath)

Description

read Fully

License

Apache License

Declaration

public static byte[] readFully(Path filePath) throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStream;

import java.nio.file.Path;

public class Main {
    public static byte[] readFully(Path filePath) throws FileNotFoundException, IOException {
        return readFully(new FileInputStream(filePath.toFile()));
    }//from   w ww  .  j  a va2 s . c  om

    public static byte[] readFully(InputStream inputStream) throws IOException {
        byte[] buffer = new byte[131072];
        int bytesRead;
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        while ((bytesRead = inputStream.read(buffer)) != -1) {
            output.write(buffer, 0, bytesRead);
        }
        return output.toByteArray();
    }
}

Related

  1. readFileToSingleString(String path)
  2. readFileToString(@Nonnull Path file)
  3. readFromFile(Path absolutePath)
  4. readFromFile(String path)
  5. readFromFile(String path)
  6. readIntsFromFile(String filePath)
  7. readJson(Class dataClass, Path path)
  8. readJsonObject(Path path, TypeReference typeReference)
  9. readKeyFile(String path)