Java Utililty Methods FileInputStream Read

List of utility methods to do FileInputStream Read

Description

The list of methods to do FileInputStream Read are organized into topic(s).

Method

voidwriteFileToOutputStream(File file, OutputStream output)
Write given file to outputstream.
byte[] buffer = new byte[4096]; 
int bytesRead;
FileInputStream input = new FileInputStream(file);
while ((bytesRead = input.read(buffer)) != -1) {
    output.write(buffer, 0, bytesRead);
voidwriteFileToStream(File file, OutputStream os)
write File To Stream
if (file == null) {
    return;
try (InputStream is = new FileInputStream(file)) {
    byte[] buff = new byte[1024];
    int read = 0;
    while ((read = is.read(buff)) != -1) {
        os.write(buff, 0, read);
...
voidwriteFileToZipStream(String path, File f, ZipOutputStream out)
write File To Zip Stream
if (f.isFile()) {
    out.putNextEntry(new ZipEntry(path + "/" + f.getName()));
    FileInputStream in = new FileInputStream(f);
    byte[] b = new byte[1024];
    int count;
    while ((count = in.read(b)) > 0) {
        out.write(b, 0, count);
    in.close();
} else if (f.isDirectory()) {
    out.putNextEntry(new ZipEntry(f.getName() + "/"));