Here you can find the source of writeFile(InputStream inputFile, String path, String fullFileName)
Parameter | Description |
---|---|
inputFile | The input file to be write into the folder. |
path | The full path where the file will be wrote. |
fullFileName | The file name with its extension name. |
Parameter | Description |
---|---|
IOException | The I/O exception. |
public static void writeFile(InputStream inputFile, String path, String fullFileName) 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 . j a v a 2 s . c o m * Writes an file in a specific folder in the web server. * * @param inputFile * The input file to be write into the folder. * @param path * The full path where the file will be wrote. * @param fullFileName * The file name with its extension name. * @throws IOException * The I/O exception. */ public static void writeFile(InputStream inputFile, String path, String fullFileName) throws IOException { // creating objects to be wrote into the folder File file = new File(path + fullFileName); OutputStream outputFile = new FileOutputStream(file); // writing the file byte per byte byte buf[] = new byte[1024]; int length; while ((length = inputFile.read(buf)) > 0) { outputFile.write(buf, 0, length); } // closing files inputFile.close(); outputFile.close(); } }