Android InputStream Save writeFile(File outputFile, InputStream inputStream)

Here you can find the source of writeFile(File outputFile, InputStream inputStream)

Description

write File

Declaration

public static void writeFile(File outputFile, InputStream inputStream) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    public static void writeFile(File outputFile, InputStream inputStream) {
        try {/*from  w ww .j  a  v a  2  s  . c  o  m*/
            // write the inputStream to a FileOutputStream
            OutputStream out = new FileOutputStream(outputFile);

            int read = 0;
            byte[] bytes = new byte[1024];

            while ((read = inputStream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }

            out.flush();
            out.close();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }
}

Related

  1. dumpToFile(File file, InputStream inputStream)
  2. saveFile(InputStream in, String fileName)
  3. saveToLocal(InputStream in, String filePath)
  4. writerFromInputStream(InputStream stream, String path, String fileName)
  5. saveFile(Context context, String fileName, InputStream inputStream)
  6. writeXmlToTempFile(InputStream xmlStream, String filePath, String closingTag)
  7. writeToString(InputStream stream)
  8. saveInputStreamAsFile(InputStream inputStream, File target)