Java Utililty Methods InputStream to File

List of utility methods to do InputStream to File

Description

The list of methods to do InputStream to File are organized into topic(s).

Method

voidinputStream2File(InputStream in, File file)
input Stream File
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
try {
    while ((bytesRead = in.read(buffer, 0, 8192)) != -1) {
        os.write(buffer, 0, bytesRead);
} finally {
...
StringInputStream2File(InputStream in, String filePath)
Input Stream File
FileOutputStream fos = null;
String fileName = filePath + File.separator + System.currentTimeMillis() + ".jpg";
try {
    int flag = 0;
    fos = new FileOutputStream(fileName);
    byte[] b = new byte[1024];
    while ((flag = in.read(b, 0, 1024)) != -1) {
        fos.write(b, 0, flag);
...
longInputStreamToFile(final InputStream stream, final File file)
Input Stream To File
final FileWriter w = new FileWriter(file);
final InputStreamReader r = new InputStreamReader(stream);
final long result = readerToWriter(new InputStreamReader(stream), w);
closeProperly(w);
closeProperly(r);
return result;
voidinputStreamToFile(InputStream byteStream, String pathFileName)
input Stream To File
InputStream bStream = null;
FileOutputStream fileOutStream = null;
try {
    bStream = byteStream;
    fileOutStream = new FileOutputStream(pathFileName);
    byte[] buffer = new byte[10];
    int nbytes = 0; 
    while ((nbytes = bStream.read(buffer)) != -1) { 
...
voidinputStreamToFile(InputStream in, File file)
input Stream To File
BufferedOutputStream out = null;
byte[] b = new byte[8192];
try {
    out = new BufferedOutputStream(new FileOutputStream(file));
    for (int n; (n = in.read(b)) != -1;) {
        out.write(b, 0, n);
} catch (Exception e) {
...
voidinputStreamToFile(InputStream ins, File file)
input Stream To File
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
    os.write(buffer, 0, bytesRead);
os.close();
ins.close();
...
voidinputstreamtofile(InputStream ins, File file)
inputstreamtofile
OutputStream os = null;
try {
    os = new FileOutputStream(file);
} catch (FileNotFoundException e) {
    e.printStackTrace();
int bytesRead = 0;
byte[] buffer = new byte[8192];
...
FileinputStreamToFile(InputStream is)
input Stream To File
File contentFile = File.createTempFile("tmpCont", ".txt");
OutputStream outputStream = null;
outputStream = new FileOutputStream(contentFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = is.read(bytes)) != -1) {
    outputStream.write(bytes, 0, read);
outputStream.close();
return contentFile;
voidinputStreamToFile(InputStream is, File targetFile)
input Stream To File
byte[] buffer = ByteStreams.toByteArray(is);
OutputStream outStream = new FileOutputStream(targetFile);
outStream.write(buffer);
outStream.flush();
outStream.close();
voidinputStreamToFile(InputStream stream, File file)
input Stream To File
FileOutputStream output = null;
try {
    output = new FileOutputStream(file);
    copyStream(stream, output);
} finally {
    if (output != null) {
        output.close();