Android File Read readFile(String filepath)

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

Description

read File

License

Open Source License

Declaration

@SuppressWarnings("resource")
public static byte[] readFile(String filepath) 

Method Source Code

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

import java.io.File;
import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.RandomAccessFile;

public class Main {

    @SuppressWarnings("resource")
    public static byte[] readFile(String filepath) {
        byte[] result = null;

        try {/* www.j  av a 2 s . co  m*/
            File file = new File(filepath);

            if (file.length() <= Integer.MAX_VALUE) {
                result = new byte[(int) file.length()];
                RandomAccessFile raf = new RandomAccessFile(file, "r");

                raf.readFully(result);
            }

        } catch (FileNotFoundException e) {
            //e.printStackTrace();
        } catch (IOException e) {
            //e.printStackTrace();
        }
        return result;
    }
}

Related

  1. read(File path, int i)
  2. readFile(File file)
  3. readFileAsString(String filePath)
  4. readFileToByte(File file)
  5. readFileToString(String fileName)
  6. readFileToString(String pathToFile)