Java FileInputStream Read readFile(String filename)

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

Description

read File

License

Creative Commons License

Declaration

static protected byte[] readFile(String filename) throws IOException 

Method Source Code


//package com.java2s;
/* Studio for kdb+ by Charles Skelton
   is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Germany License
   http://creativecommons.org/licenses/by-nc-sa/3.0
   except for the netbeans components which retain their original copyright notice
*//*ww w.  ja  va  2  s.  c om*/

import java.io.*;

public class Main {
    static protected byte[] readFile(String filename) throws IOException {
        File file = new File(filename);
        long len = file.length();
        byte data[] = new byte[(int) len];
        FileInputStream fin = new FileInputStream(file);
        int r = fin.read(data);
        if (r != len)
            throw new IOException("Only read " + r + " of " + len + " for " + file);
        fin.close();
        return data;
    }
}

Related

  1. readFile(String fileName)
  2. readFile(String filename)
  3. readFile(String fileName)
  4. readFile(String fileName)
  5. readFile(String filename)
  6. readFile(String fileName)
  7. readFile(String filename)
  8. readfile(String filename)
  9. readFile(String filename)