Java FileInputStream Read readFile(String file)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String file) 

Method Source Code


//package com.java2s;
/*//from ww w .  ja  v a  2 s  .c  o  m
 * $Header: Util.java, 21/10/2005 23:17:40 luisantonioa Exp $
 *
 * $Author: luisantonioa $
 * $Date: 21/10/2005 23:17:40 $
 * $Revision: 1 $
 * $Log: Util.java,v $
 * Revision 1  21/10/2005 23:17:40  luisantonioa
 * Added copyright notice
 *
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

import java.io.BufferedInputStream;

import java.io.File;
import java.io.FileInputStream;

public class Main {
    public static String readFile(String file) {
        File log = new File(file);
        FileInputStream fis;
        BufferedInputStream bis;
        String content = "";
        try {
            fis = new FileInputStream(log);
            bis = new BufferedInputStream(fis);
            int bytes = bis.available();
            byte[] raw = new byte[bytes];

            bis.read(raw);

            fis.close();
            bis.close();

            content = new String(raw, "UTF-8");
            //content = content.replaceAll("\r\n", "\n");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return content;
    }
}

Related

  1. readFile(final InputStream stream)
  2. readFile(final String fileNamePath)
  3. readFile(InputStream ios)
  4. readFile(InputStream iStream)
  5. readFile(String destination)
  6. readFile(String file)
  7. readFile(String file)
  8. readFile(String file)
  9. readFile(String file)