Here you can find the source of writeFile(InputStream inputStream, String filename, long lastModified)
Parameter | Description |
---|---|
content | a parameter |
filename | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static File writeFile(InputStream inputStream, String filename, long lastModified) throws IOException
//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; } }