Java File Content Read getFileContent(String path, String encoding)

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

Description

get File Content

License

Open Source License

Declaration

public static String getFileContent(String path, String encoding) 

Method Source Code

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

import java.io.*;

public class Main {
    public static String getFileContent(String path, String encoding) {
        StringBuffer sb = new StringBuffer();
        BufferedReader r = null;//from   www .j  a v  a  2s . com
        try {
            r = new BufferedReader(new InputStreamReader(
                    new FileInputStream(path), encoding));
            String line;
            while ((line = r.readLine()) != null) {
                sb.append(line);
                sb.append("\n");
            }
        } catch (FileNotFoundException e) {
            System.out.println("warning: file not found: " + path);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (r != null)
                    r.close();
            } catch (Exception e) {
            }
        }
        return sb.toString();
    }
}

Related

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