Java File Content Read getFileContent(String path)

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

Description

get File Content

License

Apache License

Declaration

public static final String getFileContent(String path) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class Main {
    public static final String getFileContent(String path) throws IOException {
        String filecontent = "";
        try {/*w  w w  .java  2s  .com*/
            File f = new File(path);
            if (f.exists()) {
                FileReader fr = new FileReader(path);
                BufferedReader br = new BufferedReader(fr);
                String line = br.readLine();

                while (line != null) {
                    filecontent += line + "\n";
                    line = br.readLine();
                }
                br.close();
                fr.close();
            }

        } catch (IOException e) {
            throw e;
        }
        return filecontent;
    }
}

Related

  1. getFileContent(String fName)
  2. getFileContent(String path)
  3. getFileContent(String path)
  4. getFileContent(String path)
  5. getFileContent(String path)
  6. getFileContent(String path, String encoding)
  7. getFileContent(String pythonSource)
  8. getFileContents(File f)
  9. getFileContents(File f)