Java FileInputStream Read readFile(String filename)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String filename) throws IOException 

Method Source Code


//package com.java2s;
/*/*from www . j a v a2 s  .  c o m*/
  werecloud provides a simple API to the VMWare vCenter data.
  Copyright (C) 2015  NigelB
    
  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 2
  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, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

import java.io.*;

public class Main {
    private static final int BLOCK_SIZE = 1024;

    public static String readFile(String filename) throws IOException {
        File d = new File(filename);
        FileInputStream fin = new FileInputStream(d);
        byte b[] = readStream(fin);
        fin.close();
        return new String(b);

    }

    public static byte[] readStream(InputStream is) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(BLOCK_SIZE);
        byte[] buffer = new byte[BLOCK_SIZE];
        int len = is.read(buffer);
        while (len > 0) {
            bos.write(buffer, 0, len);
            len = is.read(buffer);
        }
        return bos.toByteArray();
    }
}

Related

  1. readFile(String filename)
  2. readFile(String fileName)
  3. readFile(String filename)
  4. readFile(String fileName)
  5. readFile(String fileName)
  6. readFile(String filename)
  7. readFile(String fileName)
  8. readFile(String filename)
  9. readfile(String filename)