Java RandomAccessFile Read readFile(String file)

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

Description

read File

License

LGPL

Declaration

public static byte[] readFile(String file) 

Method Source Code

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

import java.io.File;

import java.io.RandomAccessFile;

public class Main {
    public static byte[] readFile(String file) {
        return readFile(new File(file));
    }// w  w  w.ja v a 2s .co  m

    public static byte[] readFile(File file) {
        byte[] fileContent = null;

        try {
            RandomAccessFile f = null;
            try {
                f = new RandomAccessFile(file, "r");
                byte[] b = new byte[(int) f.length()];

                f.read(b);
                fileContent = b;
            } finally {
                f.close();
            }
        } catch (Exception e) {

        }

        return fileContent;
    }
}

Related

  1. readFile(File f)
  2. readFile(File file)
  3. readFile(File file)
  4. readFile(final File file)
  5. readFile(String absoluteFileName)
  6. readFile(String file)
  7. readFile(String filename)
  8. readFile(String filePath)
  9. readFileByRandomAccess(String fileName)