Java InputStreamReader Read readFile(String filePath)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String filePath) 

Method Source Code


//package com.java2s;
/*/*w  w w  .  j  av  a2s  . co  m*/
 * @(#)Utils.java
 *
 * This program is version 2.0 of JDC Education Kit for Optical Experiments.
 * Copyright (C) Jasper Display Corporation 2013.
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public
 * License version 2.0 as published by the Free Software Foundation. 
    
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
 * You may contact Jasper Display Corporation by email at info@jasperdisplay.com
 * or by telephone at +1-408-855-6640.
 * More information is provided at http://www.jasperdisplay.com/.
 */

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.Reader;

public class Main {
    public static String readFile(String filePath) {
        String rs;
        FileInputStream fos;
        Reader reader;
        BufferedReader buferReader;
        StringBuilder text;
        try {
            fos = new FileInputStream(filePath);
            reader = new java.io.InputStreamReader(fos, "UTF-8");
            buferReader = new BufferedReader(reader);
            text = new StringBuilder();
            String line = null;
            while ((line = buferReader.readLine()) != null) {
                text.append(line + "\n");
            }
            reader.close();
            rs = text.toString();
        } catch (Exception ex) {
            rs = "";
            ex.printStackTrace();
        }
        return rs;
    }
}

Related

  1. readFile(String filename1)
  2. readFile(String fileNm)
  3. readFile(String filePath)
  4. readFile(String filePath)
  5. readFile(String filePath)
  6. readFile(String filePath)
  7. readFile(String filePath)
  8. readFile(String filePath, String charsetName, long lineNow, long lineEnd)
  9. readFile(String input)