Java Text File Read getFileContentAsString(File cpfile)

Here you can find the source of getFileContentAsString(File cpfile)

Description

get File Content As String

License

Open Source License

Declaration

public static String getFileContentAsString(File cpfile) 

Method Source Code

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

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    public static String getFileContentAsString(File cpfile) {
        FileReader in = null;//from ww w  .j  ava 2  s .c  o m
        try {
            in = new FileReader(cpfile);
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        char[] buffer = new char[128];
        int len;
        String content = "";
        try {
            while ((len = in.read(buffer)) != -1) {
                content += new String(buffer, 0, len);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return content.trim();
    }
}

Related

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