Java InputStreamReader Read readFileData(File file)

Here you can find the source of readFileData(File file)

Description

read File Data

License

Apache License

Declaration

public static String readFileData(File file) throws Exception 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static String readFileData(File file) throws Exception {
        StringBuilder sb = new StringBuilder();
        FileInputStream in = null;
        BufferedReader br = null;
        try {/*  ww  w . j  av  a  2 s. c  o m*/
            in = new FileInputStream(file);
            br = new BufferedReader(new InputStreamReader(in));
            String data = null;
            while ((data = br.readLine()) != null) {
                sb.append(data);
            }
        } catch (Exception e) {
            throw e;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return sb.toString();
    }
}

Related

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