Java FileInputStream Read Readfile(String path)

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

Description

Readfile

License

Apache License

Declaration

public static String Readfile(String path) 

Method Source Code


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

import java.io.File;
import java.io.FileInputStream;

import java.io.InputStream;
import java.util.ArrayList;

public class Main {
    public static String Readfile(String path) {
        try {// w w w . java  2s.co m

            StringBuffer readsb = new StringBuffer();
            InputStream in = new FileInputStream(new File(path));
            ArrayList<String> alist = new ArrayList<String>();

            int count;
            byte[] b = new byte[1024 * 1024];
            while ((count = in.read(b)) != -1) {
                if (count != b.length) {
                    byte[] t = new byte[count];
                    for (int i = 0; i < count; ++i)
                        t[i] = b[i];
                    readsb.append(new String(t));
                } else
                    readsb.append(new String(b));
            }
            in.close();
            return readsb.toString();
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
}

Related

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