Java File Content Read getFileContent(String filename)

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

Description

get File Content

License

Open Source License

Declaration

public static String getFileContent(String filename) throws IOException 

Method Source Code


//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Main {
    public static String getFileContent(String filename) throws IOException {
        File file = new File(filename);
        if (!file.exists()) {
            return null;
        }/*w  w w .  j a  va2s  .  co m*/

        FileInputStream fis = new FileInputStream(file);
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        byte[] buff = new byte[1024];
        int len = 0;
        while ((len = fis.read(buff)) != -1) {
            out.write(buff, 0, len);
        }

        out.close();
        fis.close();
        return out.toString();
    }
}

Related

  1. getFileContent(File file)
  2. getFileContent(File file)
  3. getFileContent(String filename)
  4. getFileContent(String filename)
  5. getFileContent(String fileName)
  6. getFileContent(String fileName)
  7. getFileContent(String fileName)
  8. getFileContent(String fileName)
  9. getFileContent(String fileName)