Java FileOutputStream Create writeFile(InputStream inputStream, String filename, long lastModified)

Here you can find the source of writeFile(InputStream inputStream, String filename, long lastModified)

Description

Write a file to disk

License

Open Source License

Parameter

Parameter Description
content a parameter
filename a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static File writeFile(InputStream inputStream, String filename, long lastModified) throws IOException 

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  w ww  .  ja v a2 s. c  o  m*/
     * Write a file to disk
     * 
     * @param content
     * @param filename
     * @throws IOException
     */
    public static File writeFile(InputStream inputStream, String filename, long lastModified) throws IOException {

        File file = new File(filename);
        file.createNewFile();

        OutputStream out = new FileOutputStream(file);

        byte[] bytes = new byte[4096];

        for (int len; (len = inputStream.read(bytes)) > 0;) {
            out.write(bytes, 0, len);
        }

        out.flush();
        out.close();

        if (lastModified > 0) {
            file.setLastModified(lastModified);
        }

        return file;
    }
}

Related

  1. writeFile(FileOutputStream fileoutputstream, byte abyte0[], int i)
  2. writeFile(final String filename, final byte[] data)
  3. writeFile(final String fileNamePath, final byte[] daten)
  4. writeFile(InputStream in, File file)
  5. writeFile(InputStream inputFile, String path, String fullFileName)
  6. writeFile(InputStream is, File file)
  7. writeFile(InputStream is, File outFile)
  8. writeFile(InputStream srcStream, File destFile)
  9. writeFile(InputStream stream, File to)