Java – Convert InputStream to File

This tutorial shows several ways to convert InputStream to File in Java.

1- Common way

The common way for converting InputStream to File is through using OutputStream.

You can’t directly create a File object from InputStream. However, you can read the InputStream and write it to a File using FileOutputStream as the following:

2- java.nio (Java 8)

Using nio packages exposed by Java 8, you can write an InputStream to a File using Files.copy() utility method.

3- Apache commons library

Apart from JDK, you can use apache commons library for converting InputStream to File as the following:

 

Hussein Terek

Founder of programmergate.com, I have a passion in software engineering and everything related to java environment.

You may also like...

Leave a Reply

avatar