Java Text File Read getFileContents(Reader reader)

Here you can find the source of getFileContents(Reader reader)

Description

get File Contents

License

Open Source License

Declaration

public static String getFileContents(Reader reader) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static String getFileContents(String fileName) throws Exception {
        return getFileContents(fileName, 4096);
    }/*ww  w  .jav a  2 s .  c  o  m*/

    public static String getFileContents(File file) throws Exception {
        try {
            return getFileContents(new BufferedReader(new FileReader(file), 4096));
        } catch (Exception e) {
            System.err.println("Exception getting contents for file " + file.getName() + ": " + e);
            throw e;
        }
    }

    public static String getFileContents(String fileName, int bufLen) throws Exception {
        try {
            return getFileContents(new BufferedReader(new FileReader(fileName), bufLen));
        } catch (Exception e) {
            System.err.println("Exception getting contents for file " + fileName + ": " + e);
            throw e;
        }
    }

    public static String getFileContents(Reader reader) throws Exception {
        StringBuilder sb = new StringBuilder();
        for (int c = reader.read(); c >= 0; c = reader.read()) {
            sb.append((char) c);
        }
        return sb.toString();
    }
}

Related

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