read Buffered File - Android File Input Output

Android examples for File Input Output:InputStream

Description

read Buffered File

Demo Code


//package com.java2s;
import java.io.*;

public class Main {
    public static byte[] readBufferedFile(String filename)
            throws IOException {
        File file = new File(filename);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        BufferedInputStream in = new BufferedInputStream(
                new FileInputStream(file));

        int read;
        byte[] buff = new byte[1024];
        while ((read = in.read(buff)) > 0) {
            out.write(buff, 0, read);/*from  ww w  .  j a v a2 s . com*/
        }
        out.flush();
        byte[] audioBytes = out.toByteArray();
        in.close();
        return audioBytes;
    }
}

Related Tutorials