Java FileInputStream Read writeFile(OutputStream os, File f)

Here you can find the source of writeFile(OutputStream os, File f)

Description

write File

License

Open Source License

Declaration

public static void writeFile(OutputStream os, File f) throws IOException 

Method Source Code


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

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    private static final int DEFAULT_BUFFER_SIZE = 8192;

    public static void writeFile(OutputStream os, File f) throws IOException {
        try (InputStream fis = new FileInputStream(f)) {
            writeFile(os, fis);//from   www . j a  v a  2  s. com
        }
    }

    public static void writeFile(OutputStream os, InputStream is) throws IOException {
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        os.flush();
    }
}

Related

  1. readFileToStr(String fn, String charset)
  2. readFileUTF8(String file)
  3. readFileUTF_8(String filePath)
  4. writeFile(File file, byte[] buffer, ZipOutputStream zos)
  5. writeFile(InputStream fileInputStream, OutputStream outputStream)
  6. writeFile(String path, OutputStream out)
  7. writeFileToOutputStream(File file, OutputStream output)
  8. writeFileToStream(File file, OutputStream os)
  9. writeFileToZipStream(String path, File f, ZipOutputStream out)