Java FileInputStream Read readFileAsBinary(File file)

Here you can find the source of readFileAsBinary(File file)

Description

read File As Binary

License

Open Source License

Declaration

public static String readFileAsBinary(File file) throws IOException 

Method Source Code


//package com.java2s;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

public class Main {
    public static String readFileAsBinary(File file) throws IOException {
        StringBuffer stringBuffer = new StringBuffer();
        BufferedInputStream input = null;

        try {//from www .  j a  va  2 s.c  om
            input = new BufferedInputStream(new FileInputStream(file));

            int read = 0;
            byte[] buffer = new byte[1024];
            while ((read = input.read(buffer)) != -1)
                stringBuffer.append(read);

            return stringBuffer.toString();
        } finally {
            if (input != null)
                input.close();
        }
    }
}

Related

  1. readFile(String path, String encoding)
  2. readFile(String path, String root, OutputStream out)
  3. readFile(String pPathToFile)
  4. readFile(String resource)
  5. readFile(String sFileName)
  6. readFileAsInputStream(File file)
  7. readFileAsInputStream(String fileName)
  8. readFileAsProperties(File file)
  9. readFileAsResource(String fileName)