Java InputStreamReader Read readFile(String Path)

Here you can find the source of readFile(String Path)

Description

read File

License

Open Source License

Declaration

protected static String readFile(String Path) 

Method Source Code


//package com.java2s;
/*/*from   w  w  w  .  j  a va 2 s  .  c  om*/
 * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

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

public class Main {
    protected static String readFile(String Path) {
        BufferedReader reader = null;
        String laststr = "";
        try {
            FileInputStream fileInputStream = new FileInputStream(Path);
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            reader = new BufferedReader(inputStreamReader);
            String tempString = null;
            while ((tempString = reader.readLine()) != null) {
                laststr += tempString;
            }
            reader.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                }
            }
        }
        return laststr;
    }
}

Related

  1. ReadFile(String Path)
  2. readFile(String path)
  3. readFile(String path)
  4. readFile(String path)
  5. readFile(String path)
  6. readFile(String path)
  7. readFile(String path)
  8. readFile(String path)
  9. readFile(String path, String charset)