Java FileInputStream Read readFile(String path)

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

Description

read File

License

Apache License

Declaration

public static String readFile(String path) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    public static String readFile(String path) throws IOException {
        FileInputStream in = new FileInputStream(path);
        String s = readStreamUTF8(in);
        in.close();//  w  w  w.j  av  a  2s  .  c  o m
        return s;
    }

    public static String readStreamUTF8(InputStream in) throws IOException {
        if (in == null)
            throw new IOException("in == null");
        byte[] data = readStream(in);
        return new String(data, "utf-8");
    }

    public static byte[] readStream(InputStream in) throws IOException {
        if (in == null)
            throw new IOException("in == null");
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        while ((len = in.read(buffer)) != -1) {
            bout.write(buffer, 0, len);
        }
        in.close();
        return bout.toByteArray();
    }
}

Related

  1. readFile(String fname)
  2. readFile(String imageName)
  3. readFile(String name)
  4. readFile(String path)
  5. Readfile(String path)
  6. readFile(String path)
  7. readFile(String path)
  8. readFile(String path)
  9. readFile(String path)