Java Text File Read getFileContentAsString(final String filePath)

Here you can find the source of getFileContentAsString(final String filePath)

Description

reads file and concatenate content to a string

License

Open Source License

Declaration

public static String getFileContentAsString(final String filePath)
        throws IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    /**//  ww w  .j  a va 2  s . c o  m
     * reads file and concatenate content to a string
     */
    public static String getFileContentAsString(final String filePath)
            throws IOException {
        final StringBuffer fileData = new StringBuffer(1000);
        final BufferedReader reader = new BufferedReader(new FileReader(
                filePath));
        char[] buf = new char[1024];
        int numRead = 0;
        while ((numRead = reader.read(buf)) != -1) {
            final String readData = String.valueOf(buf, 0, numRead);
            fileData.append(readData);
            buf = new char[1024];
        }
        reader.close();
        return fileData.toString();
    }
}

Related

  1. fileContentsToString(File errFile)
  2. fileContentsToString(String file)
  3. getChars(File file)
  4. getChars(Reader r)
  5. getFileContentAsString(File cpfile)
  6. getFileContentAsString(InputStream inputStream)
  7. getFileContentAsString(String path)
  8. getFileContents(Reader reader)
  9. getFileContents(String filePath)