Java ByteArrayOutputStream Write readAllFromFile(File f)

Here you can find the source of readAllFromFile(File f)

Description

read All From File

License

Open Source License

Declaration

public static String readAllFromFile(File f) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class Main {
    public static String readAllFromFile(File f) throws IOException {
        FileInputStream fis = new FileInputStream(f);
        byte[] buf = new byte[2048];
        int read;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        while ((read = fis.read(buf)) != -1) {
            bos.write(buf, 0, read);//from  ww w.  j ava  2 s .  c o m
        }
        fis.close();
        return bos.toString();

    }
}

Related

  1. readAll(InputStream stream)
  2. readAllAndClose(InputStream is)
  3. readAllAndKeepOpen(InputStream bytes, int bufferSize)
  4. readAllBinary(InputStream stream)
  5. readAllFrom(InputStream in, boolean chunked)
  6. readAllFromFile(String file)
  7. readAllTextFromResource(String resourceName)