Java FileInputStream Read readFile(String filePath)

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

Description

read File

License

Apache License

Declaration

public static String readFile(String filePath) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    public static String readFile(String filePath) throws IOException {
        File file = new File(filePath);
        FileInputStream fin = new FileInputStream(file);
        ByteArrayOutputStream bs = new ByteArrayOutputStream();

        while (true) {
            int content = fin.read();
            if (content == -1) {
                String content1 = new String(bs.toByteArray(), "UTF-8");
                fin.close();//from  ww w. ja v a  2s  .  c o m
                bs.close();
                return content1;
            }

            bs.write(content);
        }
    }
}

Related

  1. readFile(String fileName)
  2. readFile(String fileName, String charset)
  3. readFile(String filePath)
  4. readFile(String filePath)
  5. readFile(String filePath)
  6. readFile(String filePath)
  7. readFile(String filePath)
  8. readFile(String filePath)
  9. readFile(String filePathName)