Java FileOutputStream Write saveFile(InputStream uploadedInputStream, String serverLocation)

Here you can find the source of saveFile(InputStream uploadedInputStream, String serverLocation)

Description

Save uploaded file to a defined location on the server

License

Open Source License

Parameter

Parameter Description
uploadedInputStream a parameter
serverLocation a parameter

Declaration

public static void saveFile(InputStream uploadedInputStream, String serverLocation) 

Method Source Code

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

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;

public class Main {
    /**//from  www.  j  a v a 2s  . co  m
     * Save uploaded file to a defined location on the server
     * @param uploadedInputStream
     * @param serverLocation
     */
    public static void saveFile(InputStream uploadedInputStream, String serverLocation) {
        try {
            OutputStream outpuStream = new FileOutputStream(new File(serverLocation));
            int read = 0;
            byte[] bytes = new byte[1024];

            outpuStream = new FileOutputStream(new File(serverLocation));
            while ((read = uploadedInputStream.read(bytes)) != -1) {
                outpuStream.write(bytes, 0, read);
            }
            outpuStream.flush();
            outpuStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

Related

  1. saveFile(final InputStream in, final String path, final String fileName)
  2. saveFile(final String filename, final String s1, final String textOut, final String s3)
  3. saveFile(InputStream is, File file)
  4. saveFile(InputStream is, String destDir, String fileName)
  5. savefile(InputStream source, String destination)
  6. saveFile(String content, String path)
  7. saveFile(String desEncryptTempFile, byte[] text)
  8. saveFile(String destinationFile, String contents)
  9. saveFile(String dir, String fileName, String data)