Java File Content Read getFileContent(String filePath)

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

Description

get File Content

License

Apache License

Declaration

public static String getFileContent(String filePath) 

Method Source Code


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

import java.io.*;

public class Main {
    public static String getFileContent(String filePath) {
        File file = new File(filePath);
        if (!file.exists() || !file.isFile()) {
            return null;
        }/*from   ww  w .  j a v  a  2s .  c om*/

        StringBuffer content = new StringBuffer();
        try {
            char[] temp = new char[1024];
            FileInputStream fileInputStream = new FileInputStream(file);
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            while (inputStreamReader.read(temp) != -1) {
                content.append(new String(temp));
                temp = new char[1024];
            }

            fileInputStream.close();
            inputStreamReader.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return content.toString();
    }
}

Related

  1. getFileContent(String fileName)
  2. getFileContent(String fileName)
  3. getFileContent(String fileName)
  4. getFileContent(String fileName)
  5. getFileContent(String filePath)
  6. getFileContent(String filepath)
  7. getFileContent(String fName)
  8. getFileContent(String path)
  9. getFileContent(String path)