Java InputStreamReader Read readFileFromDisk(String filepath)

Here you can find the source of readFileFromDisk(String filepath)

Description

read File From Disk

License

Apache License

Declaration

public static String readFileFromDisk(String filepath) 

Method Source Code


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

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.InputStreamReader;

public class Main {

    public static String readFileFromDisk(String filepath) {
        FileInputStream fis = null;
        BufferedReader br = null;
        StringBuffer sb = new StringBuffer();
        String temp = "";
        try {//w w  w .j  a  v  a2  s . c  o m
            fis = new FileInputStream(filepath);
            br = new BufferedReader(new InputStreamReader(fis, "utf-8"));
            while ((temp = br.readLine()) != null) {
                sb.append(temp).append("\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (fis != null) {
                    fis.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return sb.toString();
    }
}

Related

  1. readFileByCharAsString(String path, String encode)
  2. readFileCharacters(File file, boolean fix)
  3. readFileData(File file)
  4. readFileData(String directoryLocation, String fileName)
  5. readFileFromClassPath(String file)
  6. readFileFromResource(@SuppressWarnings("rawtypes") Class refClass, String filePath)
  7. readFileFromResource(String filename)
  8. readFileIntoLines(File file)
  9. readFileIntoLinesOfLongs(File file)