Java FileOutputStream Write saveTo(InputStream in, String fileName)

Here you can find the source of saveTo(InputStream in, String fileName)

Description

save To

License

Open Source License

Declaration

public static void saveTo(InputStream in, String fileName) throws IOException 

Method Source Code


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

import java.io.*;

public class Main {
    public static void saveTo(InputStream in, String fileName) throws IOException {
        saveTo(in, new File(fileName));
    }//w ww .  j  av  a 2 s.co m

    public static void saveTo(InputStream in, File file) throws IOException {
        try (OutputStream out = new FileOutputStream(file)) {
            byte[] buffer = new byte[4096];
            while (true) {
                int read = in.read(buffer, 0, 4096);
                if (read <= 0) {
                    out.flush();
                    in.close();
                    out.close();
                    break;
                }

                out.write(buffer, 0, read);
            }
        }
    }
}

Related

  1. saveStringToFile(File file, String content, String charset)
  2. saveTemp(final byte[] data, final String suffix)
  3. saveTempFile(String xmlSource, String fileName)
  4. saveTextContentInFile(String content, File file)
  5. saveTextToFile(String fileName, String content)
  6. saveTo(String path, InputStream in)
  7. saveTo(String path, InputStream in)
  8. saveToBinaryFile(File dest, byte[] data)
  9. saveToDisc(final InputStream fileInputStream, final String fileUploadPath)