Here you can find the source of saveContentToFile(DataHandler content, File outFile)
Parameter | Description |
---|---|
content | The content |
outFile | The output file |
Parameter | Description |
---|---|
IOException | If an error occurs during saving |
static public long saveContentToFile(DataHandler content, File outFile) 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; import javax.activation.DataHandler; public class Main { /**//from w w w .j a v a 2 s .c o m * Saves the specified content to the specified file * @param content The content * @param outFile The output file * @throws IOException If an error occurs during saving */ static public long saveContentToFile(DataHandler content, File outFile) throws IOException { long size = 0; byte[] buffer = new byte[1024]; try (InputStream is = content.getInputStream()) { try (OutputStream outStream = new FileOutputStream(outFile)) { for (int readBytes; (readBytes = is.read(buffer, 0, buffer.length)) > 0;) { size += readBytes; outStream.write(buffer, 0, readBytes); } } } return size; } }